Python Program to Print First n Natural Numbers Using while loop

 Python Program to Print First n Natural Numbers Using while Loop


print("Python program to print first n natural numbers:")

i=1

while i<=10:

  print(i)

  i=i+1

print("End of Program")

Output:

Python program to print first n natural numbers:

1

2

3

4

5

6

7

8

9

10

End of Program


Display N natural numbers by taking user input 

print("Python program to print first n natural numbers:")

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

i=1

while i<=n:

  print(i)

  i=i+1

print("End of Program")


Output:

Python program to print first n natural numbers:

Enter Number:10

1

2

3

4

5

6

7

8

9

10

End of Program


टिप्पणी पोस्ट करा

0 टिप्पण्या