def hani(n,x,y,z):
if n == 1 :
print(x ,"-->",z)
else:
hani(n-1,x,z,y)#将n-1个盘子从x移到y
print(x,"-->",z)# 将第n个盘子从x移到z
hani(n-1,y,x,z)#将y上的n-1个盘子从y移到z n = int(input("请输入层数"))
hani(n,"x","y","z")
05-11 20:13