利用数据文件统计成绩

data = open('成绩单.csv', 'r', encoding='utf-8')
n = int(input())
ls1 = []
s = 0
ls2 = []
with open('成绩单.csv', 'r', encoding='utf-8') as f:
    for line in f.readlines():
        line = line.strip('\n')
        ls = list(line.split(','))
        ls1.append(ls)

ls1.sort(key=lambda x: eval(x[9]))

print('最低分{}分,最高分{}分'.format(ls1[0][9], ls1[len(ls1) - 1][9]))
if n <= len(ls1):
    print(ls1[:n])
    print(ls1[(len(ls1) - n):])
else:
    print(ls1)
    print(ls1)
for j in range(3, 9):
    s = 0
    for i in ls1:
        s = s + eval(i[j])
        a = s / len(ls1)
    ls2.append(eval('%.2f' % a))
print(ls2)

data.close()

你可能感兴趣的:(python)