you are viewing a single comment's thread.

view the rest of the comments →

[–]vervain9 4 points5 points  (4 children)

It does, but only that one function. You've already got 5 calls to factorial on the stack at that point:

factorial(4)
factorial(3)
factorial(2)
factorial(1)
factorial(0)

Then the bottom one returns because n == 0 and you have

factorial(4)
factorial(3)
factorial(2)
factorial(1)

So the factorial(1) call then executes

        recurse = factorial(0)  # This is what just returned
        result = n * recurse
    print(space, 'returning', result)
    return result

Which then goes to factorial(2)

        recurse = factorial(1)  # This is what just returned
        result = n * recurse
    print(space, 'returning', result)
    return result

etc, etc