I am teaching my self python 2 at the moment using exercise books. I am currently studying recursive function. I am a bit confused how the "n" value is calculated. Below as a simple example I have created for myself.
def input(x, y, n):
if n == 0:
return
print (x y), "Recurse no.", n
input(x, y, n - 1)
print (x 1), "Recurse no.", n
input(x, y, n - 1)
input(10, 6, 3)
Result | Recurse number |
---|---|
16 | Recurse no. 3 |
16 | Recurse no. 2 |
16 | Recurse no. 1 |
11 | Recurse no. 1 |
11 | Recurse no. 2 |
16 | Recurse no. 1 |
11 | Recurse no. 1 |
11 | Recurse no. 3 |
16 | Recurse no. 2 |
16 | Recurse no. 1 |
11 | Recurse no. 1 |
11 | Recurse no. 2 |
16 | Recurse no. 1 |
11 | Recurse no. 1 |
I have tried to work out the "n" manually as below be but nor sure how it woks after the first 3 rows.