誰かが私が間違っていることに気づくことができるかどうか疑問に思っています。私は次のコードが最大数と最大数のインデックスを見つける印象を受けました。ここでは以下のコードを使用しています。max()を使ってリスト内のmax()を見つけ、そのインデックス値を見つける方法?
def select_winner():
print('The game scores are:')
for i in range (4):
print(Players[i], ' = ', score[i])
winner = max(enumerate(score))
print('----------------')
print()
print('The Winner is ', Players[winner[0]], ' with ', str(winner[1]),'
points!')
print(winner)
出力:
#The game scores are:
#Jarrah = 86
#Reza = 121
#Marge = 72
#Homer = 91
#----------------
#The Winner is Homer with 91 points!
#(3, 91)
最大は最高値の右を選ぶべきなのでしょうか?誤っていない場合は値とインデックスを選択する必要があります。一緒に印刷すると、リストにある値が最も高くなるはずです。私は何をしようとしています。最も高いスコアとして選ばれたスコアのインデックスは、そのスコアを取得したプレイヤーと同じインデックスを共有する必要があります。
任意のヘルプは おかげ
アップデート素晴らしいことだ:独自のプルに
#The game scores are:
#Jarrah = 91
#Baldwin = 73
#Kepa = 112
#Long = 106
#----------------
#in select_winner
#print('The Winner is '+ Players[winner[0]]+ ' with '+ str(winner[1])+ '
#points!')
#TypeError: 'int' object is not subscriptable
誰もが周りの仕事を知っている、とmaxを(い):
def select_winner():
print('The game scores are:')
for i in range (4):
print(Players[i], ' = ', score[i])
winner =(max(score))
print('----------------')
print()
print('The Winner is '+ Players[winner[0]]+ ' with '+ str(winner[1])+ '
points!')
print(winner)
出力最大数がどこにあるかの指標ですか?もしそうでなければ、それを行う方法はありますか?
固定!:
def select_winner():
k=0
print('The game scores are:')
for i in range (4):
print(Players[i], ' = ', score[i])
winner2=(score.index(max(score)))
winner=str(max(score))
print('----------------')
print()
print('The Winner is '+ Players[winner2]+ ' with '+ winner + ' points!')
ヒント:最大試行回数 – thatrockbottomprogrammer
が試行されましたが、リスト内で最大数のインデックスも必要です –
'winner = max(列挙型、キー=ラムダx:x [1]) ' –