Squares

Report a typo

Define a generator squares that produces an infinite sequence of the squares of all natural numbers (1, 4, 9, 16, ...).

For a given number n, print out the first n elements each on a new line.

Sample Input 1:

2

Sample Output 1:

1
4

Sample Input 2:

5

Sample Output 2:

1
4
9
16
25
Write a program in Python 3
n = int(input())


def squares():
yield ...


# Don't forget to print out the first n numbers one by one here
___

Create a free account to access the full topic