让结果显示为:学号,平时成绩,期末成绩,总评成绩 9999180103,87,96,92 9999180102,91,85,87 9999180101,77,88,84 9999180105,86,72,78 9999180104,70,68,69
时间: 2023-07-27 15:25:03 浏览: 76
以下是修改后的 Python 代码:
```python
# 读取文件
with open('score.txt', 'r') as f:
lines = f.readlines()
# 计算总评成绩
scores = []
for line in lines:
info = line.strip().split(',')
num = info[0]
regular_score = int(info[1])
final_score = int(info[2])
total_score = round(regular_score * 0.4 + final_score * 0.6)
scores.append((num, regular_score, final_score, total_score))
# 按总评成绩降序排列
scores = sorted(scores, key=lambda x: x[3], reverse=True)
# 写入文件
with open('result.txt', 'w') as f:
f.write('学号,平时成绩,期末成绩,总评成绩\n')
for score in scores:
f.write('{},{},{},{}\n'.format(score[0], score[1], score[2], score[3]))
```
执行完毕后,会生成一个名为 result.txt 的文件,其中包含了按总评成绩降序排列的学生信息,包括了每个学生的学号、平时成绩、期末成绩和总评成绩。
阅读全文