SHARE
TWEET

Python Tower of Hanoi

naeem043 Oct 10th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top