PPA-1

Question

Accept a positive integer \(n\) as input and print the first \(n\) positive integers, one number on each line.

Hint

Which loop should we use here, while or for?

If we go with a for loop, is the following solution correct?

n = int(input())
for x in range(n):
    print(x)

If it is not correct, then what is the mistake?

Solutions

n = int(input())
k = 1
while k <= n:
    print(k)
    k += 1
n = int(input())
for x in range(1, n + 1):
    print(x)

Video Solution