Created
August 6, 2019 05:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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