I am practicing with some code, and one thing I am trying to do is have the Fibonacci sequence placed recursively into a list. I have managed to do it without recursion, but that is not too difficult. Thank you to anyone who can offer any help.
#python 2
arr = [1, 1]
n=15
def Fib(n):
tmp = arr[-1] + arr[-2]
if n == 0:
return 0 #base case 1
elif n == 1:
return 1 #base case 2
else:
return Fib(n-1) + Fib(n-2) #recursive call
arr.append(tmp)
return arr
Fib(n)
print arr