Objective
Create a Python program that computes the Fibonacci number n with recursion and a memory (dictionary) that avoids repeating calculations.
Instructions
- Read an integer
nbetween 0 and 50. - Define a recursive function
fib(n)withfib(0) = 0andfib(1) = 1. Before computing, check whethernis already in thememorydictionary; if not, compute it, store it and return it. - Use a global variable to count every call to
fib(all of them, including those solved with the memory). - Show
Fibonacci: Xon the first line andCalls: Kon the second.
10
Fibonacci: 55
Calls: 19
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise