def f(max): n, a, b = 0, 0, 1 while n <= max: yield b a, b = b, a + b n += 1 yield 'done' for i in f(5): print(i)