Question: Write a Python program that implements the Towers of Hanoi, using the recursive algorithm discussed in class. Use command-line arguments to pass parameters to the

Write a Python program that implements the Towers of Hanoi, using the recursive algorithm discussed in class.

Use command-line arguments to pass parameters to the program -

spring% python towersOfHanoi.py USAGE: towersOfHanoi.py    
spring% python towersOfHanoi.py 4 1 3 Move disk from peg 1 to peg 2 Move disk from peg 1 to peg 3 Move disk from peg 2 to peg 3 
Move disk from peg 1 to peg 2 Move disk from peg 3 to peg 1 Move disk from peg 3 to peg 2 Move disk from peg 1 to peg 2 Move disk from peg 1 to peg 3 Move disk from peg 2 to peg 3 Move disk from peg 2 to peg 1 Move disk from peg 3 to peg 1 

I have gotten this far with writing the program but keep getting "command not found" when trying to run the program.

Write a Python program that implements the Towers of Hanoi, using the

hanoitowers.py - Downloads 1 import sys if len (sys.argv) != 4 : print 'USAGE: python hanoitowers.py sys.exit(1) 6v def TowerOfHanoi(nRings, frompeg, topeg, auxpeg): if n == 1: print ("Move disk from peg", frompeg, "to peg", topeg) return TowerofHanoi (n-1, frompeg, auxpeg, topeg) print ("Move disk", "from peg", from_peg, "to peg", topeg), TowerofHanoi (n-1, auxpeg, topeg, frompeg), n = int(sys.argv[1]), fromPeg = int(sys.argv[2]), toPeg = int(sys.argv[3]), pegs = [1,2,3] print '# rings = ', nRings, ' from peg #', fromPeg, ' to peg #', topeg pegs.remove(frompeg) pegs. remove (topeg) auxpeg = peg [0] TowerofHanoi(n, str(frompeg), str(to_peg), str(auxpeg))||

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!