In the Spring 2013 Edition of this book, on page 50, figure 4.10. This code for the Fibonacci sequence is give.
def fib(x):
"""assumes x an int >= 0 returns Fibonacci of x """
global numCalls
numCalls += 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 numCalls
numCalls = 0
print 'fib of ', i, '=', fib(i)
print 'fib called', numCalls, 'time.'
Is there an error. Should numCalls = 0 ?

Hey! We 've verified this expert answer for you, click below to unlock the details :)

I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!

Yes. It needs to be reset every time you test it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

Looking for something else?

Not the answer you are looking for? Search for more explanations.