Answer to Question #244488 in Python for jklnjb

Question #244488

Fibonacci numbers are a sequence of integers, starting with 1, where the value of each number is the sum of the two previous numbers, e.g. 1, 1, 2, 3, 5, 8, etc. Write a function called fibonacci that takes a parameter, n, which contains an integer value, and have it return the nth Fibonacci number. (There are two ways to do this: one with recursion, and one without.)


1
Expert's answer
2021-09-30T06:42:32-0400
def fibonacci(n)
    if n ==0:
         return 0
    elif n == 1:
         return 1
    else:
         return fibonacci(n-1) + fibonacci(n-2)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS