Python Practice › Loop Programs › Program 12
Natural numbers n to 1 with while
Write a Python program to print the natural numbers from n down to 1 using a while loop.
Input
n = 10
Output
10 9 8 7 6 5 4 3 2 1
Approach
- Start at n and decrease until 0.
Solution
n = 10while n >= 1: print(n, end=" ") n -= 1print()Output
10 9 8 7 6 5 4 3 2 1
Line by line
Line 4
-= 1 counts down.
Learn the concept
New to this topic? Read the lesson, then come back.