Bird
0
0

Identify the syntax error in this code snippet:

medium📝 Debug Q6 of 15
Python - Loop Control
Identify the syntax error in this code snippet:
for i in range(4):
    if i == 2
        break
    print(i)
AMissing colon (:) after the if condition
BIncorrect indentation of print statement
CUsing break outside a loop
DRange function is used incorrectly
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of if statement

    Python requires a colon (:) at the end of the if condition.
  2. Step 2: Identify error

    The line if i == 2 is missing the colon.
  3. Final Answer:

    Missing colon (:) after the if condition -> Option A
  4. Quick Check:

    Every if statement needs a colon [OK]
Quick Trick: If statements must end with a colon [:] [OK]
Common Mistakes:
MISTAKES
  • Forgetting colon after if
  • Misplacing break outside loops
  • Incorrect indentation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes