Bird
0
0

Find the error in this code:

medium📝 Debug Q6 of 15
Python - While Loop

Find the error in this code:

counter = 1
while counter <= 3:
print(counter)
counter += 1
ACounter is not initialized
BMissing indentation inside the while loop
CLoop condition is wrong
DCounter increment is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check code indentation

    Python requires code inside loops to be indented; here print and increment are not indented.
  2. Step 2: Verify other parts

    Counter is initialized; condition and increment are correct; only indentation is wrong.
  3. Final Answer:

    Missing indentation inside the while loop -> Option B
  4. Quick Check:

    Python needs indentation inside loops [OK]
Quick Trick: Indent all code inside while loops [OK]
Common Mistakes:
MISTAKES
  • Not indenting loop body
  • Forgetting to increment counter
  • Wrong loop condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes