Print Numbers in Reverse Order in Python Using While Loop

Now we are going to Print numbers from 10 to 1 in reverse order in Python using a while loop:

Simple code:

num = 10
while num >= 1:
    print(num)
    num = num - 1

Output:

10
9
8
7
6
5
4
3
2
1


Code with comments:

#initialize the starting number to 10
num = 10
#continue looping until the number reaches 1
while num >= 1:
# print the current number
    print(num)
# decrement the number by 1
    num -= 1

Output:

10
9
8
7
6
5
4
3
2
1

In this code, we initialize the starting number to 10 and then use a while loop to continue printing numbers until we reach 1.

We print the number at each iteration of the loop and then decrement the number by 1. This results in printing the numbers in reverse order, from 10 to 1.


Discover more from Python Mania

Subscribe to get the latest posts sent to your email.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

Related Articles:

Recent Articles:

0
Would love your thoughts, please comment.x
()
x

Discover more from Python Mania

Subscribe now to keep reading and get access to the full archive.

Continue reading