Python MCQs Control Statements (if, loops)

Q1. Which keyword is used for conditional execution in Python?

A) switch
B) if
C) when
D) select
✅ Correct Answer: (B) if
📘 Explanation: if is used to test a condition and execute code accordingly.

Q2. Which statement is used when an if condition is false?

A) else
B) elseif
C) when
D) otherwise
✅ Correct Answer: (A) else
📘 Explanation: else executes when the if condition evaluates to False.

Q3. Which keyword is used to check multiple conditions?

A) else
B) elif
C) elseif
D) switch
✅ Correct Answer: (B) elif
📘 Explanation: elif allows checking multiple conditions in sequence.

Q4. Which loop is used when the number of iterations is known?

A) while
B) for
C) do-while
D) repeat
✅ Correct Answer: (B) for
📘 Explanation: The for loop is commonly used when iterations are predefined.

Q5. Which loop continues as long as a condition is true?

A) for
B) do-while
C) while
D) repeat
✅ Correct Answer: (C) while
📘 Explanation: while loops execute as long as the condition remains true.

Q6. What is the output of the following code?

for i in range(3): print(i)


A) 1 2 3
B) 0 1 2
C) 0 1 2 3
D) Error
✅ Correct Answer: (B) 0 1 2
📘 Explanation: range(3) generates values 0, 1, and 2.

Q7. Which statement is used to exit a loop immediately?

A) stop
B) exit
C) break
D) end
✅ Correct Answer: (C) break
📘 Explanation: break terminates the loop instantly.

Q8. Which statement skips the current iteration and continues with the next one?

A) skip
B) continue
C) pass
D) next
✅ Correct Answer: (B) continue
📘 Explanation: continue skips the remaining code in the loop body for the current iteration.

Q9. What does the pass statement do?

A) Stops loop
B) Skips iteration
C) Does nothing
D) Ends program
✅ Correct Answer: (C) Does nothing
📘 Explanation: pass acts as a placeholder and performs no action.

Q10. What is the output of the following code?

i = 1 while i <= 3: print(i) i += 1


A) 1 2 3
B) 0 1 2
C) Infinite loop
D) Error
✅ Correct Answer: (A) 1 2 3
📘 Explanation: The loop runs until i becomes greater than 3.

Q11. Which loop is best suited for iterating over a list?

A) while
B) for
C) do-while
D) repeat
✅ Correct Answer: (B) for
📘 Explanation: for loop is ideal for traversing sequences like lists.

Q12. What is the output of the following code?

if False: print("Hello") else: print("World")


A) Hello
B) World
C) Error
D) No Output
✅ Correct Answer: (B) World
📘 Explanation: Since the condition is False, the else block executes.

Q13. Which of the following is NOT a loop in Python?

A) for
B) while
C) do-while
D) nested loop
✅ Correct Answer: (C) do-while
📘 Explanation: Python does not support do-while loops.

Q14. What is the output of the following code?

for i in range(1, 5, 2): print(i)


A) 1 2 3 4
B) 1 3
C) 2 4
D) 1 2
✅ Correct Answer: (B) 1 3
📘 Explanation: The loop starts at 1 and increments by 2.

Q15. Which statement is used to execute code only when all conditions are false?

A) if
B) elif
C) else
D) pass
✅ Correct Answer: (C) else
📘 Explanation: else executes if none of the previous conditions are true.

Q16. What happens if the loop condition is never false?

A) Loop stops
B) Error occurs
C) Infinite loop
D) Program exits
✅ Correct Answer: (C) Infinite loop
📘 Explanation: If the condition never becomes false, the loop runs infinitely.

Q17. What is the output of the following code?

for i in range(3): if i == 1: continue print(i)


A) 0 1 2
B) 1 2
C) 0 2
D) None
✅ Correct Answer: (C) 0 2
📘 Explanation: When i == 1, the loop skips printing.

Q18. Which keyword is used to define an empty loop body?

A) continue
B) pass
C) break
D) skip
✅ Correct Answer: (B) pass
📘 Explanation: pass is used when no action is required.

Q19. What is the output of the following code?

i = 5 while i > 0: print(i) i -= 2


A) 5 3 1
B) 5 4 3 2 1
C) 5 3
D) Infinite loop
✅ Correct Answer: (A) 5 3 1
📘 Explanation: The loop decreases i by 2 each time.

Q20. Which statement is used to test multiple conditions in a single if?

A) and / or
B) else
C) pass
D) break
✅ Correct Answer: (A) and / or
📘 Explanation: Logical operators and / or are used to combine conditions.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top