Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

while loop counting by codechum admin write a program that takes an int…

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

Explanation:

Step1: Take input

n = int(input("Enter a number: "))

Step2: Initialize counter

count = 1

Step3: Use while loop

while count <= n:
    print(count)
    count += 1

Answer:

n = int(input("Enter a number: "))
count = 1
while count <= n:
    print(count)
    count += 1