Python Practice › Loop Programs › Program 12

Natural numbers n to 1 with while

EasyLoop Programs · 12 of 90

Write a Python program to print the natural numbers from n down to 1 using a while loop.

Advertisement
Input
n = 10
Output
10 9 8 7 6 5 4 3 2 1 

Approach

  1. Start at n and decrease until 0.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More loop programs

← All 90 Loop Programs