1
2 def printMove (to, fr):
3 '''Prints the moves to be executed'''
4 print 'move from ' + str (fr) + ' to ' + str (to)
5
6 def towers (n, fr, to, sp):
7 if n == 1:
8
9 printMove (to, fr) #
10
11 else:
12 towers (n-1, fr, sp, to)
13
14
15
16 towers (1, fr, to, sp)
17 towers (n - 1, sp, to, fr)
18
19 towers (3, 'fr', 'to', 'sp')
Please can someone explain why this code completes the recursive call on line 12 with n
decrementing to 1, then does another call to n = 2
again and then move to line 16 after? I have been using python tutor and am trying to understand each step and why the algorithm works.