Bird
0
0

Identify the problem in this code:

medium📝 Debug Q7 of 15
Python - For Loop
Identify the problem in this code:
for i in range(3):
print(i)
else:
    print('Finished')
Aprint statement syntax error
Belse block must be inside for loop
CIndentation error in for loop body
DMissing colon after else
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation rules

    The body of the for loop must be indented. Here, print(i) is not indented.
  2. Step 2: Verify else block placement

    The else block is correctly aligned with for and indented properly.
  3. Final Answer:

    Indentation error in for loop body -> Option C
  4. Quick Check:

    Loop body must be indented [OK]
Quick Trick: Indent loop body correctly under for [OK]
Common Mistakes:
MISTAKES
  • Not indenting loop body
  • Misaligning else block
  • Missing colon after else

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes