通过文档算学生的平均分

tom 85 90
jerry 95 80
lucy 80 90
rose 88 90
jay 76 75
summer 87 85
horry 84 80
dic = {}
with open('score.txt','r') as f:
    lines = f.readlines()
    f.close()
    for line in lines:
        line = line.strip('
').split(' ')
        dic[line[0]] = (int(line[1]),int(line[2]))
name = input()
if name not in dic.keys():
    print("not found")
else:
    print(sum(dic[name])/len(dic[name]))

2020-05-30

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12990789.html