def hanoi(n,a,b,c):
if n== 1:
print("{}->{}".format(a,c))
else:
hanoi(n-1,a,c,b)
print("{}->{}".format(a,c))
hanoi(n-1,b,a,c)
hanoi(5,‘A‘,‘B‘,‘C‘)
时间: 2024-10-01 18:44:54
def hanoi(n,a,b,c):
if n== 1:
print("{}->{}".format(a,c))
else:
hanoi(n-1,a,c,b)
print("{}->{}".format(a,c))
hanoi(n-1,b,a,c)
hanoi(5,‘A‘,‘B‘,‘C‘)