In this program, we will print all natural numbers in reverse (from n to 1) using a while loop
Steps to solve the program
- Take the last number from which you want to print the natural numbers as input through the user.
- Create a variable count and assign its value equal to the input number.
- Use a while loop to print the numbers in reverse order.
- While the count variable is not equal to 0 print count and subtracts 1 from it each time.
- Print the output.
n = int(input("Enter the last number: "))
count = n
while count != 0:
print(count,end=" ")
count -= 1
Output :
Enter the last number: 10
10 9 8 7 6 5 4 3 2 1