def fib(num): a = 0 b = 1 for i in range(num): yield a a, b = b, a + b # Adds values together then swaps them for x in fib(100): print(x)