Python练习题11:汉诺塔实践
程序员文章站
2024-03-05 15:26:55
...
steps = 0
def hanoi(src,des,mid,n):
global steps
if n == 1:
steps += 1
print("[STEP{:>4}] {}->{}".format(steps,src,des))
else:
hanoi(src,mid,des,n-1)
steps += 1
hanoi(mid,des,src,n-1)
n = eval(input())
hanoi("A","C","B",n)