Mastering Python Control Flow: Intermediate Challenges
Test your understanding of Python control flow with these intermediate-level challenges.
Questions in this quiz
12 questions on Mastering Python Control Flow: Intermediate Challenges. Work through them here, then start the quiz to answer them and see your score.
1.What will be the output of the following code snippet? ```python x = 5 y = 10 if x > y: print('x is greater') elif x < y: print('x is smaller') else: print('x equals y') ```
- ANo output
- Bx equals y
- Cx is smaller
- Dx is greater
2.Consider the following code. What will be the output? ```python for i in range(3): if i == 1: continue print(i) ```
- A1 2
- B0 1 2
- C0 1
- D0 2
3.What will be the output of this code snippet? ```python x = 0 while x < 3: print(x) x += 1 else: print('Done') ```
- A0 1 2
- B0 1 2 3
- CDone
- D0 1 2 Done
4.What is the output of the following code? ```python for i in range(5): if i == 3: break print(i) ```
- A0 1 2
- B0 1 2 3 4 5
- C0 1 2 3 4
- D0 1 2 3
5.What will the following code output? ```python x = 10 y = 20 if x > 5: if y < 15: print('A') else: print('B') else: print('C') ```
- AC
- BA
- CB
- DNo output
6.What will be the output of this code? ```python for i in range(3): for j in range(2): print(i, j) ```
- A0 0 0 1 1 0 1 1 2 0 2 1
- B0 0 1 0 2 0
- C0 1 1 2 2 3
- D0 0 1 1 2 2
7.What will be printed by this code? ```python x = 1 while x < 5: print(x) x += 2 ```
- A1 2 3 4
- B1 3
- C1 2 3
- D1 3 5
8.What will be the output of this code snippet? ```python x = 0 while True: x += 1 if x == 3: break print(x) ```
- A1 2 3 4 5
- B1 2
- C1 2 3
- D1 2 3 4
9.What will be the result of the following code? ```python x = 10 y = 5 if x > y: print('x is greater') else: print('y is greater') ```
- Ay is greater
- Bx equals y
- CNo output
- Dx is greater
10.What will be the output of this code? ```python for i in range(4): if i % 2 == 0: print(i) ```
- A0 1 2 3
- B1 3
- C0 1 2
- D0 2
11.What will be printed by this code? ```python x = 0 while x < 3: x += 1 if x == 2: continue print(x) ```
- A1 2
- B2 3
- C1 3
- D1 2 3
12.What will be the output of this code snippet? ```python x = 5 y = 10 if x < y: print('x is smaller') else: print('x is greater') ```
- Ax is smaller
- Bx is greater
- Cx equals y
- DNo output