Bird
0
0

What will be printed by this code?

medium📝 Predict Output Q5 of 15
Python - For Loop
What will be printed by this code?
for i in range(5, 0, -1):
    print(i, end=' ')
A5 4 3 2 1 0
B5 4 3 2 1
C0 1 2 3 4 5
D1 2 3 4 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand range with negative step

    range(5, 0, -1) counts down from 5 to 1 (stop excluded).
  2. Step 2: List values generated

    Values are 5, 4, 3, 2, 1 printed with spaces.
  3. Final Answer:

    5 4 3 2 1 -> Option B
  4. Quick Check:

    Negative step counts down, stop excluded [OK]
Quick Trick: Negative step counts down, stop is excluded [OK]
Common Mistakes:
MISTAKES
  • Including stop value
  • Counting up instead of down
  • Confusing step sign

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes