Search code examples
pythonloopswhile-loop

Print even numbers n number of times, using while loop


Task

Write a Python script which reads a positive integer n from standard input and outputs the first n even natural numbers, one per line.

(Take the natural numbers to be 1, 2, 3, 4, and so on.)

I'm a beginner to Python, so I need to use a while loop, without for or in.

We learned:

while i < n:
   print i
   i = i + 1

So need a variation of that for this answer.


Solution

  • You need to print 2 times i for each i.

    n = int(input())
    
    i = 1
    while i <= n:
       print(2*i)
       i = i + 1