#漢諾達遊戲 def hanni(n,x,y,z): if n == 1: print(x,'-->',z) else: hanni(n-1,x,z,y)#n-1移動到y print(x,'-->',z) hanni(n-1,y,x,z)#n-1移動到z n = int(input("請輸入漢諾塔的層數:")) hanni(n,'X','Y','Z')