Print all natural numbers from 1 to n

In this program, we will print all natural numbers from 1 to n using a while loop.

Steps to solve the program
  1. Take the number up to which you want to print natural numbers from the user.
  2. Create a variable count and assign its value equal to 1.
  3. Use a while loop to print the natural numbers up to the input number.
  4. While the value of the count variable is less than the input number print count and add 1 to the count variable.
  5. Print the output.
				
					n = int(input("Enter the last number: "))
count = 1

while count <= n:
    print(count,end=" ")
    count += 1
				
			

Output :

				
					Enter the last number: 10
1 2 3 4 5 6 7 8 9 10 
				
			

print the alphabet pattern ‘O’

print all natural numbers in reverse

Leave a Comment