In this Python program, we will learn how to print the natural numbers in a given range.
Here is the code of the program to print the natural numbers in a given range.
# Python Program to Print Natural Numbers from 1 to Nth
# To Take input from the User
num = int(input("Enter any Number: "))
print("The List of Natural Numbers from 1 to {0} are".format(num))
for i in range(1, num + 1):
print (i, end = ' ')
Enter any Number: 10
The List of Natural Numbers from 1 to 10 are
1 2 3 4 5 6 7 8 9 10
# Python Program to Print Natural Numbers from 1 to Nth
# To Take input from the User
num = int(input("Enter any Number: "))
i = 1
print("The List of Natural Numbers from 1 to {0} are".format(num))
while ( i <= num):
print (i, end = ' ')
i = i + 1
Enter any Number: 10
The List of Natural Numbers from 1 to 10 are
1 2 3 4 5 6 7 8 9 10
# Python Program to Print Natural Numbers within a given range
minNum = int(input("Enter the Minimum integer Value : "))
maxNum = int(input("Enter the Maximum integer Value : "))
print("The List of Natural Numbers from {0} to {1} are".format(minNum, maxNum))
for i in range(minNum, maxNum + 1):
print (i, end = ' ')
Enter the Minimum integer Value : 5
Enter the Maximum integer Value : 20
The List of Natural Numbers from 5 to 20 are
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Comments