Skip to content

Instantly share code, notes, and snippets.

@edenau
Created February 23, 2020 23:57
Show Gist options
  • Save edenau/c6551854a50bdfb7a8cafdc98a516d71 to your computer and use it in GitHub Desktop.
Save edenau/c6551854a50bdfb7a8cafdc98a516d71 to your computer and use it in GitHub Desktop.
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