I'm working with a basic Python MIT free courseware and I have run into a wall with a recursion exercise. The original program takes an integer and provides its Fibonacci using recursion. The book provides the script for the program, but the subsequent exercise asks to input a way for the program to recognize how many times fib(2) is executed on its way to calculating fib(n). I'm hoping to get some help because I've been stuck on this for about a week now.
Here is the code:
def fib(n):
"""Assumes n is int > 0
Returns Fibonacci Number of n"""
if n ==0 or n==1:
return n
else:
return fib(n-1) + fib(n-2)
def testfib(n):
for i in range(n+1):
print('fib of', i, 'is ', fib(i))
x=int(input('Enter a number: '))
print('Fibonacci of', x, 'is',fib(x))
print(testfib(x))
Reference: Introduction to Computation and Programming Using Python, Figure 4.7
n == 2