On 10/12/2013 14:48, uga...@talktalk.net wrote:

[snipped]

As you're clearly struggling here's my attempt at showing you what is happening.

c:\Users\Mark\MyPython>type mytest.py
level = 0

def mult(a, b):
    global level
    level += 1
    print('level now', level, 'a =', a, 'b =', b)
    if b == 0:
        print('immediate return as b == 0')
        return 0
    print('call mult again')
    rest = mult(a, b - 1)
    print('rest =', rest)
    value = a + rest
    print('value =', value, '(a + rest ==',a, '+', rest,')')
    return value
mult(3, 2)

c:\Users\Mark\MyPython>mytest.py
level now 1 a = 3 b = 2
call mult again
level now 2 a = 3 b = 1
call mult again
level now 3 a = 3 b = 0
immediate return as b == 0
rest = 0
value = 3 (a + rest == 3 + 0 )
rest = 3
value = 6 (a + rest == 3 + 3 )

c:\Users\Mark\MyPython>

Does this help clarify things for you?

--
My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to