Bird
0
0

Find the error in this code:

medium📝 Debug Q14 of 15
Python - For Loop
Find the error in this code:
for i in range(5, 1):
    print(i)
ANo error, prints 5 to 1
BSyntaxError due to wrong range syntax
CLoop does not run because start > stop without step
DInfinite loop
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the range parameters

    range(5, 1) means start at 5, stop before 1, with default step 1.
  2. Step 2: Understand loop behavior

    Since start is greater than stop and step is positive, the loop runs zero times.
  3. Final Answer:

    Loop does not run because start > stop without step -> Option C
  4. Quick Check:

    range(5,1) empty range [OK]
Quick Trick: Positive step needs start < stop to run [OK]
Common Mistakes:
MISTAKES
  • Expecting loop to run backwards
  • Thinking syntax error occurs
  • Assuming infinite loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes