Quote (ringo794 @ Sep 23 2013 08:27pm)
I am still absolutely lost. I can easily say print Fib(5) and get the fifth term of the fibonacci sequence, but I have no idea what kind of statement to put to make it print out all of the first twenty terms.
dont print the function, print inside the function
Code
def Fib(n):
int returnvalue = 0
if n ==0:
returnvalue = 0
elif n ==1:
returnvalue = 1
else:
returnvalue = Fib(n-1)+Fib(n-2)
print returnvalue
return returnvalue
keep in mind you won't see each one just once with this method. you'll see it multiple times. to fix this, you need to calculate each fib(n) only once, then print it and cache it. every time you use it without calculating it (eg: pull from cache), you will not print it.