Python Program to Print Natural Numbers

21-Oct-2022

.

Admin

Python Program to Print Natural Numbers

Hi Dev,

In this short tutorial we will cover an Python Program to Print Natural Numbers. We will look at example of Python Program to Print Numbers From N to 1 and 1 to N. We will look at example of Python Program to print N Natural numbers. This post will give you simple example of Print First 10 Natural Numbers in Python. So, let's follow few step to create example of Write a program to print first n numbers in python.

Python Program to Print Numbers From N to 1 and 1 to N

let's see below simple example with output:

Example 1: Python program to print numbers from 1 to N using for loop


# Python program to print numbers from 1 to n

n = int(input("Please Enter any Number: "))

print("The List of Natural Numbers from 1", "to", n)

for i in range(1, n + 1):

print (i, end = ' ')

Output:

Please Enter any Number: 10

The List of Natural Numbers from 1 to 10

1 2 3 4 5 6 7 8 9 10

Example 2: Python program to print numbers from n to 1 using while loop

# Python program to print numbers from n to 1

number = int(input("Please Enter any Number: "))

i = number

while ( i >= 1):

print (i, end = ' ')

i = i - 1

Output:

Please Enter any Number: 8

8 7 6 5 4 3 2 1

I hope it can help you...

#Python