Advertisement
Newtrat

Fibonacci Series Generator Function

Apr 15th, 2016
3,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 0.29 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment
Advertisement