13.5k views
5 votes
Complete computeFibonacci() to return FN, where F0 is 0, F1 is 1, F2 is 1, F3 is 2, F4 is 3, and continuing: FN is FN-1 + FN-2.

1 Answer

0 votes

Answer:

def computeFibonacci(n):

if n == 0:

return 0

if n == 1:

return 1

else:

return computeFibonacci(n-1) + computeFibonacci(n-2)

Step-by-step explanation:

*The code is in Python.

Create a function called computeFibonacci that takes one parameter, n

If n is equal to 0, return 0

If n is equal to 1, return 1

Otherwise, return the total of the previous two numbers by calling the functions with parameters n-1 and n-2

User Douglas Rosebank
by
7.4k points