A box containing another smaller boxes with recursion n


#1

Hi guys!
Here is a code i can’t understand. There is a box containing another smaller boxes with recursion n. Here is the code:

def box(n):
    if n == 1:
        print("Smallest box")
    else:
        print("Top of a box ",n)
        box(n-1)
        print("Down of a box ",n)

box(int(input()))

Please could you explain me why it works this way, when n is reaching 1.


#2

you can visualize python code here:

http://www.pythontutor.com/visualize.html#mode=display

or otherwise, this topic might help:

Recursive function calls

recursion can be a tricky concept