Adding through recursion

bonono at gmail.com bonono at gmail.com
Fri Nov 18 08:30:38 EST 2005


any change you want to have :

"return add(x,y)" in the else ?


martin.clausen at gmail.com wrote:
> 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