OneCompiler

mgw TH

135
 
def tower_of_hanoi(n, source, target, spare):
    if n > 0:
        
        tower_of_hanoi(n-1, source, spare, target)

        print(f"Move disk {n} from {source} to {target}")

        tower_of_hanoi(n-1, spare, target, source)

num_disks = 3
tower_of_hanoi(num_disks, 'A', 'C', 'B')