私は、リストが最小から最大になるまでリストの2つの場所を交換するようにユーザに要求するコードを作成しています。だから、それは次のようになります。ユーザのソートリストを最小から最大にする
Hello: Your current list is [6, 7, 8, 2 , 9, 10, 12, 15, 16, 17]
Please pick your first location -> 4
Please pick your second location -> 2
Your new list is [6, 2, 8, 7 , 9, 10, 12, 15, 16, 17]
を私はこの部分を得ているが、私は現在のソートではなく、コードを実行するためにユーザーを取得する方法を見つけ出すことができません。ここで
Your list is not sorted: Please continue
Please pick your first location -> 1
Please pick your second location -> 2
Your new list is [2, 6, 8, 7 , 9, 10, 12, 15, 16, 17]
Please pick your first location -> 3
Please pick your second location -> 4
Your new list is [2, 6, 7, 8 , 9, 10, 12, 15, 16, 17]
Great job, thank you for sorting my list.
は私のコードです:
list = [4,2,5,5,6,4,7,6,9,5]
print("Heres your current list", list)
print("Pick a location between 1 and 10")
num = int(input())
if num <= 10 and num >= 1:
print("Please pick another location between 1 and 10")
num1 = int(input())
tempBox1 = list[num-1]
tempBox2 = list[num1-1]
list[num-1] = tempBox2
list[num1-1] = tempBox1
print("Your new list is", list)
してください[編集]ので、あなたのインデントが正しいです。タブの代わりにスペースを使用してください。 –
'list'をソートして' sorted_list'のような変数に設定し、何をしているのかを確認するだけでなく、 'list'が' sorted_list'と等しくなるまで各ユーザの入力をチェックしてください。 – davedwards
'list'を変数として使用する識別子が誤解を招く可能性があります。代わりに 'lst'、' L'、 'my_list'などを使用してください。 – Tonechas