Advertisement
Newtrat

Fibonacci Series Generator Function

Apr 15th, 2016
1,513
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def fib():
  2.     a, b = 0L, 1L       # The 'L's make the numbers double word length (typically 64 bits)
  3.     while true:
  4.         yield b
  5.         a, b = b, a + b
  6.  
  7. # Print the first 5 numbers in the series:
  8. for index as int, element in zip(range(5), fib()):
  9.     print("${index+1}: ${element}")
Advertisement
RAW Paste Data Copied
Advertisement