QuizzesPython Control Flow: Beginner's Guide
beginner
python

Python Control Flow: Beginner's Guide

A quiz to test your understanding of Python control flow structures.

15 minutes 15 questions Pass at 70%
Time Limit
15 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

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. 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. 2.Which keyword is used to start a loop that iterates over a sequence?

    • Aloop
    • Biterate
    • Cfor
    • Dwhile
  3. 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. 4.Which of the following statements is used to exit a loop prematurely?

    • Aexit
    • Bbreak
    • Ccontinue
    • Dstop
  5. 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. 6.Which keyword is used to skip the current iteration of a loop?

    • Apass
    • Bcontinue
    • Cbreak
    • Dskip
  7. 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. 8.Which of the following is a valid way to start a conditional statement?

    • Aswitch
    • Bif
    • Cwhen
    • Dcase
  9. 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. 10.Which statement is used to handle exceptions in Python?

    • Ahandle
    • Btry
    • Ccatch
    • Dexcept
  11. 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. 12.Which keyword is used to define an alternative block of code if a condition is false?

    • Aexcept
    • Belif
    • Cotherwise
    • Delse
  13. 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. 14.Which of the following is NOT a loop structure in Python?

    • Awhile
    • Bforeach
    • Cdo-while
    • Dfor
  15. 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