Q1. Which keyword is used for conditional execution in Python?
✅ Correct Answer: (B) if
📘 Explanation: if is used to test a condition and execute code accordingly.
📘 Explanation: if is used to test a condition and execute code accordingly.
Q2. Which statement is used when an if condition is false?
✅ Correct Answer: (A) else
📘 Explanation: else executes when the if condition evaluates to False.
📘 Explanation: else executes when the if condition evaluates to False.
Q3. Which keyword is used to check multiple conditions?
✅ Correct Answer: (B) elif
📘 Explanation: elif allows checking multiple conditions in sequence.
📘 Explanation: elif allows checking multiple conditions in sequence.
Q4. Which loop is used when the number of iterations is known?
✅ Correct Answer: (B) for
📘 Explanation: The for loop is commonly used when iterations are predefined.
📘 Explanation: The for loop is commonly used when iterations are predefined.
Q5. Which loop continues as long as a condition is true?
✅ Correct Answer: (C) while
📘 Explanation: while loops execute as long as the condition remains true.
📘 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)
✅ Correct Answer: (B) 0 1 2
📘 Explanation: range(3) generates values 0, 1, and 2.
📘 Explanation: range(3) generates values 0, 1, and 2.
Q7. Which statement is used to exit a loop immediately?
✅ Correct Answer: (C) break
📘 Explanation: break terminates the loop instantly.
📘 Explanation: break terminates the loop instantly.
Q8. Which statement skips the current iteration and continues with the next one?
✅ Correct Answer: (B) continue
📘 Explanation: continue skips the remaining code in the loop body for the current iteration.
📘 Explanation: continue skips the remaining code in the loop body for the current iteration.
Q9. What does the pass statement do?
✅ Correct Answer: (C) Does nothing
📘 Explanation: pass acts as a placeholder and performs no action.
📘 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
✅ Correct Answer: (A) 1 2 3
📘 Explanation: The loop runs until i becomes greater than 3.
📘 Explanation: The loop runs until i becomes greater than 3.
Q11. Which loop is best suited for iterating over a list?
✅ Correct Answer: (B) for
📘 Explanation: for loop is ideal for traversing sequences like lists.
📘 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")
✅ Correct Answer: (B) World
📘 Explanation: Since the condition is False, the else block executes.
📘 Explanation: Since the condition is False, the else block executes.
Q13. Which of the following is NOT a loop in Python?
✅ Correct Answer: (C) do-while
📘 Explanation: Python does not support do-while loops.
📘 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)
✅ Correct Answer: (B) 1 3
📘 Explanation: The loop starts at 1 and increments by 2.
📘 Explanation: The loop starts at 1 and increments by 2.
Q15. Which statement is used to execute code only when all conditions are false?
✅ Correct Answer: (C) else
📘 Explanation: else executes if none of the previous conditions are true.
📘 Explanation: else executes if none of the previous conditions are true.
Q16. What happens if the loop condition is never false?
✅ Correct Answer: (C) Infinite loop
📘 Explanation: If the condition never becomes false, the loop runs infinitely.
📘 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)
✅ Correct Answer: (C) 0 2
📘 Explanation: When i == 1, the loop skips printing.
📘 Explanation: When i == 1, the loop skips printing.
Q18. Which keyword is used to define an empty loop body?
✅ Correct Answer: (B) pass
📘 Explanation: pass is used when no action is required.
📘 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
✅ Correct Answer: (A) 5 3 1
📘 Explanation: The loop decreases i by 2 each time.
📘 Explanation: The loop decreases i by 2 each time.
Q20. Which statement is used to test multiple conditions in a single if?
✅ Correct Answer: (A) and / or
📘 Explanation: Logical operators and / or are used to combine conditions.
📘 Explanation: Logical operators and / or are used to combine conditions.