[colug-432] Code check: Recursion

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Sat Aug 3 02:45:10 EDT 2013


On Sat, 3 Aug 2013 01:03:01 -0400, Tom Hanlon <tom at functionalmedia.com> wrote:

> Or how do I do a recursive function call without
> blowing away changes to the string ?

Each recursive call has its own variables. 
Play with the following. 

def factorial(n):
    if n > 1:
        return n * factorial(n - 1)
    return 1

factorial(4)

or

def factorial(n):
    print 'in:', n
    if n > 1:
        i = n * factorial(n - 1)
        print 'out:', i
        return i
    print 'out:', 1
    return 1

factorial(4)

You have similar issues with recursion in your own code. 



More information about the colug-432 mailing list