python:遞歸函數(漢諾塔)

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")
相關文章
相關標籤/搜索