我知道这是一个简单的错误,但一直在看它!我在哪里添加float或int以防止出现以下错误消息? int对象不是可用的。使用字典时int对象不可迭代
如何从最高分到最低分打印它。我可以添加reverse = True吗?我收到一个元组错误。 -
scores = {} #You'll need to use a dictionary to store your scores;
with open("classscores1.txt") as f:
for line in f:
name, score = line.split() #store the name and score separately (with scores converted to an integer)
score = int(score)
if name not in scores or scores[name] < score:
scores[name] = score # replacing the score only if it is higher:
for name in sorted(scores):
print(name, "best score is", scores[name])
print("{}'s best score is {}".format(name, max(scores[name])))
'int'对象在任何地方都不可迭代*。 – jonrsharpe
'max(scores [name])'在这里,'scores [name]'只是一个单独的分数,一个'int'。这应该是该名称的分数列表吗? –
最后一行,大概是引发错误的那一行,看起来应该和以前的行完全一样。所以你可能应该删除那个有问题的行。 –