最簡單的python語言實作漢諾塔游戲
實作代碼
def hanoi(n,ch1,ch2,ch3):
if n==1:
print(ch1, '->', ch3)
else:
hanoi(n - 1, ch1, ch3, ch2)
print(ch1, '->', ch3)
hanoi(n - 1, ch2, ch1, ch3)
plate_nums = int(input("請輸入盤子的數量:"))
hanoi(plate_nums, 'A', 'B', 'C')
運行結果(顯示漢諾塔操作程序)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/340842.html
標籤:其他
