Created
February 23, 2020 23:57
-
-
Save edenau/c6551854a50bdfb7a8cafdc98a516d71 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 fibonacci(n): | |
assert n >= 0 and int(n) == n, 'Fibonacci number is defined for non-negative indices only!' | |
if n in [0,1]: | |
return n | |
else: | |
a,b = 0,1 | |
for _ in range(1,n): | |
c = a + b | |
a = b | |
b = c | |
return c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment