QUESTION IMAGE
Question
item 2
10 points
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
Step1: Get user input
n = int(input("Enter a number: "))
Step2: Initialize counter
i = 1
Step3: Use while loop
while i <= n:
print(i)
i += 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: "))
i = 1
while i <= n:
print(i)
i += 1