Infinite Generator

Lab Python Intermediate 20 points

Write an infinite generator fibonacci(). Read n and print the first n Fibonacci numbers using itertools.islice.

Input

One integer.

Output

One line.

Example

Input

10

Output

0 1 1 2 3 5 8 13 21 34
Sample input available Sample output available
Editor
Python

Hints

while True with yield inside never ends - the caller decides how many values to take.

islice(gen, n) takes the first n.

Solution explanation

Infinite generators are safe because values are only computed when requested.

Show solution
from itertools import islice


def fibonacci():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b


print(*islice(fibonacci(), int(input())))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD