我创建的代码会向用户询问一些问题。他们输入他们的名字和一个类,然后将这些信息存储到csv文件中。然后,我创建了一个显示分数和名称的新文档,尽管我希望将分数存储在名称旁边,从最高到最低。该程序我也想只显示每个用户的最后三个分数。
这是我目前的代码:
import csv
all_students = []
all_scores = []
file = (open('ELZ.csv'))
every_test = csv.reader(file)
for row in every_test:
if all_students.count(row[0]) == 0:
all_students.append(row[0])
all_scores.append(row)
else:
pos = all_students.index(row[0])
score = all_scores[pos]
score.append(row[1])
if len(score) > 4:
del(score[1])
all_scores[pos] = score
summery = []
for i in range(0, len(all_students)):
student_row = [None] * 3
input_row=all_scores[i]
for j in range(1,len(input_row)):
input_row[j] = (int(input_row[j]))
student_row[0] = input_row.pop(0)
student_row[1] = (max(input_row))
student_row[2] = (sum(input_row))
print(student_row)
summery.append(student_row)
print(summery)
from operator import itemgetter
print(sorted(summery, key=itemgetter(0)))
print(sorted(summery, key=itemgetter(1)))
print(sorted(summery, key=itemgetter(2)))
`
这是我收到的错误消息:
Traceback (most recent call last):
File "C:\Users\charlotte lily\Documents\python\python unicorns.py", line 62, in <module>
input_row[j] = (int(input_row[j]))
ValueError: invalid literal for int() with base 10: