Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def fib(x): Assumes x an int >=0 Returns Fibonacci of global numFibcalls numFibcalls += 1 if x == 0 or x == 1: return

def fib(x): """Assumes x an int >=0 Returns Fibonacci of """ global numFibcalls numFibcalls += 1 if x == 0 or x == 1: return 1 else: return fib(x-1) +fib(x-2) def testfib(n): for i in range(n+1): global numFibcalls numFibcalls = 0 print ('fib of', i, '=', fib(i)) print ('fib called', numFibCalls, 'times.')

For the code above modify it so that it will recursively calculate the values of fib(3) through fib(17), and print these values to the command console. Your modified code MUST ALSO CALCULATE the total number of times that fib(2) is called, for each computed value of fib(3) through fib(15) printed to the command console. Your output should look like the following (where the answers for fib(3), fib(4) and fib(5) are already given):

 The value of fib(3) is: 3 The total number of function calls to fib(2) was: 1 The value of fib(4) is: 5 The total number of function calls to fib(2) was: 2 The value of fib(5) is: 8 The total number of function calls to fib(2) was: 3 

Please help and I need this in python ASAP (i should have an output like the above and explain in between lines!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago