Python Control Flow: Beginner's Guide
A quiz to test your understanding of Python control flow structures.
Questions in this quiz
15 questions on Python Control Flow: Beginner's Guide. Work through them here, then start the quiz to answer them and see your score.
1.What is the output of the following code snippet? ```python x = 5 if x > 3: print('Greater') else: print('Smaller') ```
- AGreater
- BError
- CSmaller
- DNone
2.Which keyword is used to start a loop that iterates over a sequence?
- Aloop
- Biterate
- Cfor
- Dwhile
3.What will be the output of the following code? ```python for i in range(3): print(i) ```
- A0 1 2
- B1 2 3
- C3 2 1
- D0 1 2 3
4.Which of the following statements is used to exit a loop prematurely?
- Aexit
- Bbreak
- Ccontinue
- Dstop
5.What is the output of the following code? ```python x = 10 if x < 5: print('Low') elif x < 15: print('Medium') else: print('High') ```
- AMedium
- BLow
- CError
- DHigh
6.Which keyword is used to skip the current iteration of a loop?
- Apass
- Bcontinue
- Cbreak
- Dskip
7.What will be the output of the following code? ```python x = 0 while x < 3: print(x) x += 1 ```
- A3 2 1
- B0 1 2 3
- C0 1 2
- D1 2 3
8.Which of the following is a valid way to start a conditional statement?
- Aswitch
- Bif
- Cwhen
- Dcase
9.What is the output of the following code? ```python for i in range(2, 5): print(i) ```
- A1 2 3 4
- B3 4 5
- C2 3 4 5
- D2 3 4
10.Which statement is used to handle exceptions in Python?
- Ahandle
- Btry
- Ccatch
- Dexcept
11.What will be the output of the following code? ```python x = 7 if x % 2 == 0: print('Even') else: print('Odd') ```
- ANone
- BEven
- CError
- DOdd
12.Which keyword is used to define an alternative block of code if a condition is false?
- Aexcept
- Belif
- Cotherwise
- Delse
13.What is the output of the following code? ```python for i in range(1, 4): if i == 2: continue print(i) ```
- A1 2
- B1 2 3
- C1 3
- D2 3
14.Which of the following is NOT a loop structure in Python?
- Awhile
- Bforeach
- Cdo-while
- Dfor
15.What will be the output of the following code? ```python x = 3 if x > 5: print('High') else: print('Low') ```
- AHigh
- BError
- CNone
- DLow