Python For Beginners to Practice |
In this article, we are going to write a Python program to print numbers in reverse order using a while loop. First, we will print the reverse count of numbers 10 to 1. Then we will write a program to print the reverse of the numbers using the user's input.
If you are looking for a python tutorial series then it's here
count = 10
while True:
print(count)
count -= 1
if count == 0:
break
else:
pass
The output of the code is:
10
9
8
7
6
5
4
3
2
1
If you want to take input of integer from the user then you can do this using the following way:
count = int(input("Enter the number: "))
while True:
print(count)
count -= 1
if count == 0:
break
else:
pass
The output of the code is:
Enter the number: 20
20
19
18
17
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
Comments
Post a Comment