大概就是图片里面的题目,因为这节课我缺了,所以关于文件的实在不会,希望能给解答一下,最好能有注释,没有也没关系
有用请采纳
def getScore(fileName): # 传入文件路径
with open(fileName, 'r', encoding='utf-8') as f:
scores = f.readlines()
scores = [float(each) for each in scores] # 将字符转变为数
maxScore, minScore, allScore = -1, 11, 0 # 记录最大最小分以及总分
for each in scores:
allScore += each
if each > maxScore:
maxScore = each
if each < minScore:
minScore = each
print("平均分:{:.2f}".format((allScore - maxScore - minScore) / 8))
getScore('score.txt')