Question: Python Coding Problem # ###### QUESTION 7 Recursive function ########## # Write a recursive function that calculates the Fibonancci sequence. # The recusive relation is

Python Coding Problem

# ###### QUESTION 7 Recursive function ##########

# Write a recursive function that calculates the Fibonancci sequence.

# The recusive relation is fib(n) = fib(n-1) + fib(n-2),

# and the typically choice of seed values are fib(0) = 0, fib(1) = 1.

# From there, we can build fib(2) and onwards to be

# fib(2)=1, fib(3)=2, fib(4)=3, fib(5)=5, fib(6)=8, fib(7)=13, ...

# Let's set it up from here:

def fib(n):

"""

Finding the Fibonacci sequence with seeds of 0 and 1

The sequence is 0,1,1,2,3,5,8,13,..., where

the recursive relation is fib(n) = fib(n-1) + fib(n-2)

:param n: the index, starting from 0

:return: the sequence

"""

# assume n is positive integer

# ?????? fill in your codes here

return # return what ????

# Try:

print(fib(6)) # should gives 8

print(fib(7)) # should gives 13

Python Coding Problem # ###### QUESTION 7 Recursive function ########## # Write

# ###### QUESTION 7 Recursive function ########## # Write a recursive function that calculates the Fibonancci sequence. # The recusive relation is fib(n) = fib(n-1) + fib(n=2), # and the typically choice of seed values are fib(0) = 0, fib(1) = 1. # From there, we can build fib(2) and onwards to be # fib(2)=1, fib(3)=2, fib(4)=3, fib(5)=5, fib(6)=8, fib(7)=13, ... # Let's set it up from here: def fib(n): Finding the Fibonacci sequence with seeds of 0 and 1 The sequence is 0,1,1,2,3,5,8,13,..., where the recursive relation is fib(n) = fib(n-1) + fib(n-2), :param n: the index, starting from 0 :return: the sequence # assume n is positive integer # ?????? fill in your codes here return # return what ????, # Try: print(fib(6)) print(fib(7)) # should gives 8 # should gives 13

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!