def fibonacci(n):
    a, b = 0, 1
    while n:
        a, b = b, a + b
        n -= 1
    return a

for n in range(10):
    print(fibonacci(n))

[fibonacci(n) for n in range(10)]

"""
Explanation: The classic Fibonacci generator example
First, a plain function to generate the Nth number in the Fibonacci series:
End of explanation
"""


def gen_fibo(n):
    a, b = 0, 1
    while n:
        yield a
        a, b = b, a + b
        n -= 1

g10 = gen_fibo(10)
g10

f10 = list(g10)
f10

for n in gen_fibo(n):
    print(n)

"""
Explanation: The generator
Now, a generator function
End of explanation
"""


f10 = list(gen_fibo(10))
ratios = [a/b for a, b in zip(f10[2:], f10[1:-1])]
ratios

φ = (1 + 5**0.5) / 2
φ

%matplotlib inline

import matplotlib.pyplot as plt

plt.figure()
plt.plot(ratios)
plt.axhline(φ, color='r')

"""
Explanation: Fibonacci numbers and the golden ratio
End of explanation
"""


