python fibonacci get nth element

Solutions on MaxInterview for python fibonacci get nth element by the best coders in the world

showing results for - "python fibonacci get nth element"
Juan Manuel
19 May 2019
1# Dynamic approach to get nth fibonacci number
2arr = [0,1]
3
4def fibonacci(n):
5   if n<0:
6      print("Fibbonacci can't be computed")
7   elif n<=len(arr):
8      return arr[n-1]
9   else:
10      temp = fibonacci(n-1)+fibonacci(n-2)
11      arr.append(temp)
12      return temp
13
14print(fibonacci(9))