Write a program Tower of Hanoi


Topic: Write a program Tower of Hanoi

Solution

def hanoi(x):
    global repN
    repN += 1
    if x == 1:
        return 2
    
    else:
        return 3*hanoi(x-1) + 2
    
x = int(input("ENTER THE NUMBER OF DISKS: "))
global repN
repN =0
print('NUMBER OF STEPS: ', hanoi(x), ' :', repN)



List all Python Programs