Control Structures – Multiple Choice Questions (MCQs)
-
-
14. What is the output of the following code? `for i in range(5): if i == 3: continue; print(i)`?
-
15. What is the purpose of the `pass` statement in Python?
-
16. What will be the output of the following code? `x = 5; if x > 3:` (What is the expected indentation for the next line of code?)
-
17. Which of the following is NOT a valid control flow statement in Python?
-
18. What will be the output of the following code? `x = 10; while x > 0: x -= 2; if x == 4: break; print(x)`?
-
19. Which function can be used to iterate over both the index and the value of a sequence in a 'for' loop?
-
20. Which keyword is used to define a block of code to be executed if a loop finishes normally (without a 'break')?
-
21. What will be the output of the following code? `for i in range(3): print(i) else: print('Loop finished')`?
-
22. What will be the output of the following code? `for i in range(3): if i == 1: break; print(i) else: print('Loop finished')`?
-
23. Can you have nested 'if' statements in Python?
-
24. Can you have nested loops in Python?