title: How does n increase its value from 0 to 1 or 2 in the Tower of Hanoi problem?
body: <p>I am having trouble understanding how recursion works in the Tower of Hanoi problem. I am using the print function on line two to help me understand what is happening to n. My question is how does n become 1 or 2 in the output when there is only -1 in the function? I am having some serious difficulty in understanding recursion but I believe this is the easiest problem to work with to figure it out.</p>
  <pre><code>def hanoi(n,f,h,t):
      print(&quot;{}n={}, f={}, h={}, t={}&quot;\
            .format(&quot; &quot;*(4-n),n,f,h,t))
      if n == 0:
          return
      else:
          hanoi(n-1,f,t,h)
          print(f&quot;Move disk from {f} to {t}&quot;)
          hanoi(n-1,h,f,t)
      
  hanoi(3, &quot;A&quot;,&quot;B&quot;,&quot;C&quot;)
  </code></pre>
  <p>The output is this:</p>
  <pre><code> n=3, f=A, h=B, t=C
    n=2, f=A, h=C, t=B
     n=1, f=A, h=B, t=C
      n=0, f=A, h=C, t=B
  Move disk from A to C
      n=0, f=B, h=A, t=C
  Move disk from A to B
     n=1, f=C, h=A, t=B
      n=0, f=C, h=B, t=A
  Move disk from C to B
      n=0, f=A, h=C, t=B
  Move disk from A to C
    n=2, f=B, h=A, t=C
     n=1, f=B, h=C, t=A
      n=0, f=B, h=A, t=C
  Move disk from B to A
      n=0, f=C, h=B, t=A
  Move disk from B to C
     n=1, f=A, h=B, t=C
      n=0, f=A, h=C, t=B
  Move disk from A to C
      n=0, f=B, h=A, t=C
  </code></pre>
  <p>Many thanks in advance</p>