Skip to content

Instantly share code, notes, and snippets.

@BenMaydan
Created August 6, 2019 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMaydan/bc5d35000a76c175e5908338c761e587 to your computer and use it in GitHub Desktop.
Save BenMaydan/bc5d35000a76c175e5908338c761e587 to your computer and use it in GitHub Desktop.
A new way of calculating fibonnaci numbers. This is a python generator function. Example is included
def fib(stop):
"""
A generator function for fibonnaci
:return:
"""
times = 0
prev_prev = 1
prev = 0
fib_num = 0
while times < stop:
yield fib_num
fib_num = prev + prev_prev
prev_prev = prev
prev = fib_num
times += 1
for num in fib(10):
print(num)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment