count 通し番号をつけたい
python3でハノイの塔のプログラムを作っています
移動と円盤の間に1、2、3と移動回数を表示させたいです
該当のソースコード
python
1def main(): 2 n= int(input("枚数:")) 3 print("開始:") 4 moved(n,"A","B","C") 5 t= 2**n-1 6 print("移動回数は:",t) 7def moved(n, fromt, tot, witht): 8 if n == 1: 9 print("移動", ?, ":円盤", n, "を", fromt, "から", tot, "へ") 10 11 else: 12 count 13 moved(n-1, fromt, witht, tot) 14 print("移動", ?, ":円盤", n, "を", fromt, "から", tot, "へ") 15 moved(n-1, witht, tot, fromt) 16 17 18 19 20main()
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。