QUESTION IMAGE
Question
while loop counting
by codechum admin
write a program that takes an integer n.use a while loop to
count from 1 to n (inclusive), and print each number on a new
line.
sample output 1
enter a number: 10
1
2
3
4
5
6
7
8
9
10
sample output 2
enter a number: 7
1
2
3
4
5
6
7
sample output 3
enter a number: 15
Step1: Take input
n = int(input("Enter a number: "))
Step2: Initialize counter
count = 1
Step3: Use while loop
while count <= n:
print(count)
count += 1Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
n = int(input("Enter a number: "))
count = 1
while count <= n:
print(count)
count += 1