Tower of Hanoi in DSA Python

Program 1

# Program for Tower of Hanoi
import os 

def move(n,a,b,c):
    if(n==1):
        print("Move Disk %d  from %s to %s "%(n,a,c))
    else:
        move(n-1,a,c,b) # Recursion
        print("Move Disk %d  from %s to %s "%(n,a,c))
        move(n-1,b,a,c) # Recursion
     

os.system('cls')
n=int(input("Enter Number of disk"))
move(n,"A","B","C")

 

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *