Adding through recursion

Tim Williams (gmail) tdwdotnet at gmail.com
Fri Nov 18 11:46:49 EST 2005


On 18 Nov 2005 06:30:58 -0800, martin.clausen at gmail.com <
martin.clausen at gmail.com> wrote:
>
> > I still don't get it. I tried to test with x = 0 and found that to


Informative print statements can help you to see and understand the program
flow, especially if the problem is conceptual, with no *real* errors in your
"script"

def add(x, y):
print 'P1:', x,y
if x == 0:
print 'P2:', y
return y
else:
x -= 1
y += 1
print "P3:",x,y
add(x, y)
print "p4"
print 'P5'
#implied return is here, so I will add it
return # returns None **to the next level up**

print add(2, 4)

>>> reload(addtest)
P1: 2 4
P3: 1 5
P1: 1 5
P3: 0 6
P1: 0 6
P2: 6
p4
P5
p4
P5
None
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051118/786b1900/attachment.html>


More information about the Python-list mailing list