Hi,
I cannot figure out why my fib problem is giving me the output below. I just want it to print when the fib is called and the value of n, when it returns and with what value of n, and the return value.
This is what I have so far:
import math
def fib(n):
print "Computing fib:", n
if 0 < n < 3:
value = 1
print "Returning value: ", value
elif n == 0:
value = 0
print "Returning value: ", value
else:
value = fib(n-1)+fib(n-2)
return value
def main():
n = input("Enter a positive number: ")
fib(n)
main()
Why does it keep returning to the first print statement? I don't understand what I am doing wrong. Plus I did have it printing out the return value of fib(4) or 3 -- at the end of the output but now I can"t even get it to do that. Can someone help please.
This is my output:
====
>>>
Enter a positive number: 4
Computing fib: 4
Computing fib: 3
Computing fib: 2
Returning value: 1
Computing fib: 1
Returning value: 1
Computing fib: 2
Returning value: 1
>>>
Thanks!