Question: I am new to Python and learning about functions. I came across the following function and at my wits end understanding how it works. It seems to me no matter the value of `b`, the answer should always be six but that isn't the case.

***CODE***

```
def mult(a, b):
    if b == 0:
        return 0
    rest = mult(a, b - 1)
    value = a + rest
    return value
print "3 * 2 = ", mult(3, 2)

```

My understanding of what happens

1. Since `b` is not 0 it proceeds
2. `rest` is assigned the value `3, 1` and it runs the function again
3. Since `b` is 1 and does to equate to 0, it proceeds to `rest`
4. `rest` is assigned the value `3, 0` and it runs the function again
5. Since `b` is now zero it returns the value 0
6. It then proceeds to `value` which has the value 3 + 3 as `a` had the value of 3 and `rest` had the value of 3 i.e. `(3,0)`
7. It returns the value 6

**But** if I assign `mult(3,4)`, it returns the value 12. Following my understanding, that isn't possible. Clearly, I am not understanding the logic flow. What am I doing wrong?

Answer: 
The basic logic of this function is:

Let's (add `a` and subtract `1` from `b`) until `b == 0`. It might make more sense to you like this:

```
def mult(a, b):
    value = 0
    while b > 0:
        b = b - 1
        value = value + a
    return value

```

Only in stead of a while loop, your function keeps calling itself. I managed to contact `mult` himself and he was willing to explain:

> 
> Hi, my name is mult and I'm a Recurser. Recursers are a common breed
>  in Computer Sciencia and we have a special feature; we can clone
>  ourselves. Sadly I was cursed with the inability to multiply. Still, I
>  wanted to live my dream as a multiplier and I did manage to find a way
>  to do it. Here's how:
> 
> 
> When you asks me to multiply `(a, b)`, I spawn one clone
>  and ask him `(a, b - 1)`. The clone repeats this process until
>  a clone is spawned that gets asked (`a`, `0`). When that happens
>  (there is a line of myself + `b` clones then), he answers to the
>  clone that spawned him: `0`. That clone in turn adds `a` to what he
>  was just told (the first time would be `0 + a`) and answers this to
>  the clone in front of him. This process repeats until I get answered
>  by the clone I spawned myself. I add `a` to that and return this as a final
>  answer to you!
> 
> 
> 

```
def mult(a, b):
    # Should I ask a clone?
    if b == 0:
        # No! I reply 0 to my asker.
        return 0

    # Yes! I spawn a clone and ask him (a, b - 1) and wait for an answer to
    # store in 'rest'
    rest = mult(a, b - 1)

    # I take the answer and add to it the 'a' I was told
    value = a + rest

    # I return the value I calculated to my asker
    return value

print "3 * 2 = ", mult(3, 2)  # Here someone asks me (3, 2)

```
Here is a way to visually see how the recursion works:

```
COUNTER = 0

def mult(a, b):
    global COUNTER

    COUNTER+=1
    print " "*COUNTER + "Called with", a,b

    if b == 0:
        return 0
    rest = mult(a, b - 1)
    value = a + rest

    COUNTER -= 1
    print " "*COUNTER, "Value:", value 

    return value

print "3 * 4 = "
print mult(3, 4)

```

Output

```
3 * 4 = 
 Called with 3 4
  Called with 3 3
   Called with 3 2
    Called with 3 1
     Called with 3 0
     Value: 3
    Value: 6
   Value: 9
  Value: 12
12

```

You can see how the call stack goes all the way down to the bottom (b==0), and then returns values back up the chain to the top.