Showing posts with label Control. Show all posts
Showing posts with label Control. Show all posts

Monday, September 14, 2026

Python Control Flow Quiz

 Python Control Flow Quiz


1. What is the output? x = 10 if x > 5: print("A") else: print("B")

   A. B

   B. No output

   C. Error

   D. A


2. What is the output? x = 15 if x < 10: print("Low") elif x < 20: print("Medium") else: print("High")

   A. Low

   B. B

   C. Medium

   D. High


3. What is the output? for i in range(3): print(i) else: print("Done")

   A. 0 1 2

   B. Done 0 1 2

   C. 0 1 Done

   D. 0 1 2 Done


4. What is the output? for i in range(5): if i == 2: break print(i)

   A. 0 1 2

   B. 0 1 2 3 4

   C. 0 1

   D. 2 3 4


5. What is the output? for i in range(5): if i == 2: continue print(i)

   A. 0 1

   B. 2 3 4

   C. 0 1 2 3 4

   D. 0 1 3 4


6. What is the output? for i in range(3): if i == 1: break else: print("Done")

   A. 0 1

   B. Done

   C. 0 Done

   D. 0


7. What is the output? x = 0 if x: print("True") else: print("False")

   A. True

   B. Error

   C. 0

   D. False


8. What is the output? for i in range(4): if i % 2 == 0: continue print(i)

   A. 2 3

   B. 0 2

   C. 1 3

   D. 0 1 2 3


9. What is the output? for i in range(3): print(i) if i == 1: break else: print("Done")

   A. 1

   B. 0 1

   C. 0

   D. 0 1 Done


10. What is the output? x = 20 if x < 10: print("A") elif x < 20: print("B") elif x == 20: print("C") else: print("D")

   A. C

   B. D

   C. A

   D. B