# L-41 MCS 260 Fri 22 Apr 2016 : fibyield.py
"""
The Fibonacci numbers are the sequence 0, 1, 1, 2, 3, 5, 8, ...
where the next number in the sequence is the sum of the previous
two numbers in the sequence.
This script illustrates the use of yield.
"""
def fib(k):
    """
    Computes the k-th Fibonacci number, for k > 1
    """
    (prevnum, nextnum) = (0, 1)
    for i in range(k):
        (prevnum, nextnum) = (nextnum, prevnum + nextnum)
        yield nextnum

def main():
    """
    Prompts the user for a number n and
    prints the first n Fibonacci numbers.
    """
    nbr = int(input('give a natural number n : '))
    fibgen = fib(nbr)
    fibnums = [next(fibgen) for i in range(nbr)]
    print(fibnums)

main()
