【发布时间】:2021-07-22 06:47:58
【问题描述】:
如果我打开一个包含人名及其分数的文本文件,如果有 2 个人都得分最高,我如何打印这两个名字。现在它只打印其中一个名称,我希望它打印两个,其他一切正常。提前致谢!!
这是我现在的代码:
maxName = ''
maxScore = 0
for line in file:
i = line.strip().split()
x = [int(y) for y in i[1:]]
#print(z[0]," made ","$",sum(x))
if sum(x) >= maxScore:
maxName = z[0]
maxScore = sum(x)
print(f'The max total score is {maxScore}')
print(f'those who scored the highest: {maxName}')
【问题讨论】:
标签: python python-3.x file for-loop tuples