Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - Loop Control
Find the error in this code:
for i in range(3):
if i == 1:
    break
print(i)
AMissing colon after for loop
BIncorrect indentation of if and break
Cbreak cannot be used in for loops
Dprint statement should be inside the loop
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation rules in Python

    Python requires the code inside loops and conditionals to be indented properly.
  2. Step 2: Identify indentation error

    The if and break lines are not indented inside the for loop.
  3. Final Answer:

    Incorrect indentation of if and break -> Option B
  4. Quick Check:

    Indentation error = Incorrect indentation of if and break [OK]
Quick Trick: Indent inside loops and conditionals correctly [OK]
Common Mistakes:
MISTAKES
  • Not indenting if inside for loop
  • Misplacing break outside loop
  • Confusing syntax errors with logic errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes