Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q7 of 15
Python - While Loop
Identify the error in this code snippet:
num = 1
while num <= 3:
print(num)
num += 1
AThe while condition should use '<' instead of '<='
BThe print statement is not indented inside the while loop
CThe variable 'num' is not initialized
DThe increment statement should be before the print
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation

    Python requires the code inside loops to be indented.
  2. Step 2: Analyze the snippet

    The print statement is not indented, causing a syntax error.
  3. Final Answer:

    The print statement is not indented inside the while loop -> Option B
  4. Quick Check:

    Indentation defines loop body [OK]
Quick Trick: Indent all statements inside while loops [OK]
Common Mistakes:
MISTAKES
  • Forgetting to indent loop body
  • Misplacing increment statements
  • Incorrect loop condition operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes