A recursive Fibonacci
def fibo(n):
if n in (1,2):
return 1
return fibo(n-1) + fibo(n-2)
print(fibo(5)) # 5
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
def fibo(n):
if n in (1,2):
return 1
return fibo(n-1) + fibo(n-2)
print(fibo(5)) # 5