Advertisement
naeem043

Python Tower of Hanoi

Oct 10th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. n = int(input('Enter the number of disk: '))
  2. total_move = pow(2,n)-1;
  3. print("Total Moves = "+str(total_move)+"\nHere the steps for moving disks from A to C:");
  4. def moveTower(n,source, aux, destination):
  5.     if n >= 1:
  6.         moveTower(n-1,source,destination,aux)
  7.         print("moving disk from",source,"to",destination)
  8.         moveTower(n-1,aux,source,destination)
  9.  
  10. moveTower(n,"A","B","C")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement