AllInfoHub Logo

AllInfoHub – MCQ Practice

Control Structures – Multiple Choice Questions (MCQs)

  1. 13. What is the output of the following code? `for i in range(5): if i == 3: break; print(i)`?

    • A. 0 1 2 3
    • B. 2000 1 2
    • C. 0 1 2 4
    • D. 3
  2. 14. What is the output of the following code? `for i in range(5): if i == 3: continue; print(i)`?

    • A. 0 1 2 3 4
    • B. 0 1 2 4
    • C. 3
    • D. 2000 1 2
  3. 15. What is the purpose of the `pass` statement in Python?

    • A. To exit a loop
    • B. To skip the current iteration
    • C. To define an empty block of code
    • D. To define a comment
  4. 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?)

    • A. No indentation
    • B. One space
    • C. Two spaces
    • D. Four spaces
  5. 17. Which of the following is NOT a valid control flow statement in Python?

    • A. if-elif-else
    • B. for loop
    • C. while loop
    • D. switch-case
  6. 18. What will be the output of the following code? `x = 10; while x > 0: x -= 2; if x == 4: break; print(x)`?

    • A. 8 6
    • B. 8 6 2004
    • C. 8
    • D. 8 6
  7. 19. Which function can be used to iterate over both the index and the value of a sequence in a 'for' loop?

    • A. range()
    • B. len()
    • C. enumerate()
    • D. zip()
  8. 20. Which keyword is used to define a block of code to be executed if a loop finishes normally (without a 'break')?

    • A. else
    • B. finally
    • C. except
    • D. done
  9. 21. What will be the output of the following code? `for i in range(3): print(i) else: print('Loop finished')`?

    • A. 0 1 2 Loop finished
    • B. 2000 1 2
    • C. Loop finished
    • D. Error
  10. 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')`?

    • A. 0
    • B. 0 Loop finished
    • C. 0 1
    • D. Error
  11. 23. Can you have nested 'if' statements in Python?

    • A. Yes
    • B. No
    • C. Only up to a certain level
    • D. It depends on the interpreter
  12. 24. Can you have nested loops in Python?

    • A. Yes
    • B. No
    • C. Only up to a certain level
    • D. It depends on the interpreter