Towers of Hanoi – Python lab program

def TowerOfHanoi(n , source, destination, temp):
    if n == 1:
        print ("Move disk 1 from rod",source,"to rod",destination)
        return
    TowerOfHanoi(n-1, source, temp, destination)
     print ("Move disk",n,"from rod",source,"to rod",destination)
    TowerOfHanoi(n-1, temp, destination, source)

n = int(input('Enter the number of disk '))
TowerOfHanoi(n, 'source', 'destination', 'temp')

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.