Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q14 of 15
Python - While Loop
Find the error in this code snippet:
i = 1
while i < 5:
print(i)
    i += 1
AIndentation error inside the loop
BMissing colon after while condition
CVariable i is not initialized
DInfinite loop because i never changes
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation of loop body

    Python requires the code inside the while loop to be indented equally. Here, print(i) is not indented properly.
  2. Step 2: Verify other parts

    Colon is present, variable i is initialized, and i increments, so no infinite loop.
  3. Final Answer:

    Indentation error inside the loop -> Option A
  4. Quick Check:

    Loop body must be indented [OK]
Quick Trick: Indent all loop lines equally to avoid errors [OK]
Common Mistakes:
MISTAKES
  • Not indenting loop body
  • Forgetting colon after while
  • Assuming variable needs declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes