title: python tower of hanoi endless last move
body: <p>for school we have to make a python script of the tower of hanoi. now this is not really hard and I know how to do this but I wanted to make a step counter in it. and now that i did it like in the code below it does not stop making the last move. this has the result that it overflows the input.</p>
  
  <p>can you guys see whats wrong with it because I can't figure it out?</p>
  
  <pre><code>def hanoi(disk, start='START', end='END', middle='MIDDLE'):
      count = 0
      busy = "true"
      while busy == "true":
          if disk &gt; 0:
              hanoi(disk - 1, start, middle, end)
              print('Move disk' + str(disk) + ' from ' + start + ' to ' + end)
              hanoi(disk - 1, middle, end, start)
              count = count + 1
          elif disk == 0:
              busy = "false"
  
  
          print (count)
  
  if __name__ == '__main__':
      hanoi(int(input('How many disks you wanna play? ')))
  </code></pre>
  
  <p>after asking here and a bit of help from my teacher I found the problem: the correct code is below:</p>
  
  <pre><code>count = 0
  
  def increment():
      global count
      count = count+1
  
  def hanoi(disk, start='START', end='END', middle='MIDDLE'):
  
      if disk &gt; 0:
          hanoi(disk - 1, start, middle, end)
          print('Move disk' + str(disk) + ' from ' + start + ' to ' + end)
          increment()
          hanoi(disk - 1, middle, end, start)
  
  
  
  if __name__ == '__main__':
      hanoi(int(input('How many disks you wanna play? ')))
  
  print (count)
  </code></pre>
  
  <p>thanks for the help you all.</p>