Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Print Numbers from 10 Down to 1

Count backward from ten to one with Python range. Students trace a negative step, an excluded lower stop, and why the direction of a range must match its step.

BeginnerPhase 2 - Level 1: Basic LoopingExample 6 of 14
print-numbers-from-10-down-to-1.py
1# Print numbers 10 to 1
2for i in range(10, 0, -1):
3 print(i)

Output

10
9
8
7
6
5
4
3
2
1

In this one

  • Choose a negative step
  • Read descending bounds
  • Exclude the lower stop

How it works

  1. 1

    Start i at ten.

  2. 2

    Decrease it by one while above zero.

  3. 3

    Print each value before the next step.

Edge cases

Is zero displayed?

Is zero displayed?

No. The loop ends before its stop value.

What if the step were positive one?

What if the step were positive one?

The range would be empty for these bounds.

What's going on

A negative step makes i decrease after each iteration. range(10, 0, -1) begins at ten and stops before reaching zero.

The ten values print on ten lines. The stop is still excluded even though the direction is reversed. A positive step with these same bounds would produce no values, because it could never approach the lower stop.

Is zero displayed? No. The loop ends before its stop value.

What if the step were positive one? The range would be empty for these bounds.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Which value is printed last?

Pick an answer to check it.

Question 2

Is zero displayed?

Pick an answer to check it.

Questions people ask

Is zero displayed?

No. The loop ends before its stop value.

What if the step were positive one?

The range would be empty for these bounds.

Which value is printed last?

1.