In this program, we will print all natural numbers from 1 to n using a while loop.
Steps to solve the program
- Take the number up to which you want to print natural numbers from the user.
- Create a variable count and assign its value equal to 1.
- Use a while loop to print the natural numbers up to the input number.
- While the value of the count variable is less than the input number print count and add 1 to the count variable.
- 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