nth fibonacci number python code example
Example: python fibonacci get nth element
# Dynamic approach to get nth fibonacci number
arr = [0,1]
def fibonacci(n):
if n<0:
print("Fibbonacci can't be computed")
elif n<=len(arr):
return arr[n-1]
else:
temp = fibonacci(n-1)+fibonacci(n-2)
arr.append(temp)
return temp
print(fibonacci(9))