Write a fibonacci function that takes a number n (serial number) and returns a number from a list of Fibonacci numbers. Solve the problem with recursion. Hint: Fibonacci numbers are a sequence of numbers where each element is calculated as the sum of the previous two. The sequence itself starts like this: 0, 1, 1, 2, 3, 5, 8, 13, ...
Example: answer = fibonacci(5) print(answer) # 3
answer = fibonacci(6) print(answer) #5
I did it, but I don't know how to make a list start with zero Can you help me?
def fibonacci(n):
if n in (1, 2):
return 1
return fibonacci(n - 1) + fibonacci(n - 2)
n = int(input("n = "))
print(fibonacci(n))
nis 1 you should return0, ifnis 2 you should return1.