A link to the section I have a question about. Think Python - chapter 6, section 5
This code has me lost. When run, it finds n!, but I don't know how. The part I think I'm misunderstanding is the "recurse = factorial(n-1)" line.
def factorial(n):
if n == 0:
return 1
else:
recurse = factorial(n-1)
result = n * recurse
return result
Doesn't that call the function and send it back the top? (obviously not, but I'm not sure why not).
Also, after the function finishes breaking down the factors (3! into 3, 2, 1, 1), it then multiplies them. Where is it remembering them?
I'm sure this is simple, but it's got me stumped.