;

Python Program to Print Natural Numbers in Reverse Order


Tutorialsrack 22/04/2020 Python

In this Python program, we will learn how to print the natural numbers in reverse order.

Here is the code of the program to print the natural numbers in reverse order.

Program 1: Python Program to Print Natural Numbers in Reverse Order Using While Loop

Python Program to Print Natural Numbers in Reverse Order Using While Loop
# Python Program to Print Natural Numbers in Reverse Order

# To Take Input From the User
number = int(input("Enter any Number: "))
i = number

print("List of Natural Numbers from {0} to 1 in Reverse Order: ".format(number)) 

while ( i >= 1):
    print (i, end = '  ')
    i = i - 1
Output

Enter any Number: 10

List of Natural Numbers from 10 to 1 in Reverse Order: 

10  9 8  7 6 5  4 3 2 1

Program 2: Python Program to Print Reverse Order Natural Numbers within a Specific Range

Python Program to Print Reverse Order Natural Numbers within a Specific Range

Python Program to Print Reverse Order Natural Numbers within a Specific Range

# To Take Input From the User
maxNum = int(input("Enter the Maximum integer Value: "))
minNum = int(input("Enter the Minimum integer Value: "))

print("List of Natural Numbers from {0} to {1} : ".format(maxNum, minNum)) 

while ( maxNum >= minNum):
    print (maxNum, end = '  ')
    maxNum = maxNum - 1
Output

Enter the Maximum integer Value: 15

Enter the Minimum integer Value: 5

List of Natural Numbers from 15 to 5 : 

15  14 13  12 11 10  9 8 7 6 5


Related Posts



Comments

Recent Posts
Tags