Adding through recursion

martin.clausen at gmail.com martin.clausen at gmail.com
Fri Nov 18 08:22:47 EST 2005


There is problaly a really simple answer to this, but why does this
function print the correct result but return "None":

def add(x, y):
    if x == 0:
        print y
        return y
    else:
        x -= 1
        y += 1
        add(x, y)

print add(2, 4)

result:
6
None

Martin




More information about the Python-list mailing list