fibonacci.py 329 B

123456789
  1. def fib():
  2. a, b = 0, 1
  3. while True: # First iteration:
  4. yield a # yield 0 to start with and then
  5. a, b = b, a + b # a will now be 1, and b will also be 1, (0 + 1)
  6. for index, fibonacci_number in zip(range(100), fib()):
  7. print('{i:3}: {f:3}'.format(i=index, f=fibonacci_number))