Created
June 8, 2020 09:49
-
-
Save abhi923/fa4dab6e9520661adecc0e35a8c1333d to your computer and use it in GitHub Desktop.
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(n): | |
if n < 1: | |
return None | |
if n < 3: | |
return 1 | |
elem1 = elem2 = 1 | |
sum = 0 | |
for i in range(3, n + 1): | |
sum = elem1 + elem2 | |
elem1, elem2 = elem2, sum | |
return sum | |
for n in range(1, 10): # testing | |
print('fib', n, "->", fib(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment