1 #hanoi.py 2 def hanoi(n,x,y,z): 3 if n==1: 4 print(x,"-->",z) 5 else: 6 hanoi(n-1,x,z,y) 7 print(x,"-->",z) 8 hanoi(n-1,y,x,z) 9 hanoi(2,"X","Y","Z") 10 print("----------") 11 hanoi(3,"X","Y","Z")
结果如下:
原文地址:https://www.cnblogs.com/xier/p/10416082.html
时间: 2024-10-17 08:51:44