Question: Exercise 2 . Fibonacci sequence ( 5 5 pts ) . The famous Fibonacci Sequence is the series of numbers like this: 0 , 1
Exercise Fibonacci sequence pts
The famous Fibonacci Sequence is the series of numbers like this: The next number is found by adding up the two numbers prior to it is found by adding the two numbers before it is found by adding the two numbers before it is
An implementation could be like this:
def fibonaccinum:
if num :
return num
return fibonaccinum fibonaccinum
But the runtime performance is terrible. This is because the code keeps recalculating Fibonacci numbers that are already known.
Implement a @cache decorator that will save the calculations in a function attribute dictionary. Even though the function fibonaccinum only has one input argument, please make the decorator work for functions with any number of arguments the decorators own arguments can be ignored
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
