5. Fibonacci Number
In [1]:
Copied!
def fibonacci_number(n):
"""
0, 1, 1, 2, 3, 5, 8, 13, 21,...
"""
if n == 0:
return 0
if n == 1:
return 1
ans = fibonacci_number(n - 1) + fibonacci_number(n - 2)
return ans
def fibonacci_number(n):
"""
0, 1, 1, 2, 3, 5, 8, 13, 21,...
"""
if n == 0:
return 0
if n == 1:
return 1
ans = fibonacci_number(n - 1) + fibonacci_number(n - 2)
return ans
In [6]:
Copied!
fibonacci_number(8)
fibonacci_number(8)
Out[6]:
21
In [ ]:
Copied!