with open('./score.txt', 'r') as f: lines = f.readlines() scores = [] for line in lines: scorelist = line.strip().split(',')[1:] scoreint = [int(score) for score in scorelist] scores.append(scoreint) for i in range(3): playerscore = [] for grade in scores: playerscore.append(grade[i]) maxplayerscore = max(playerscore) minplayerscore = min(playerscore) playerscore.remove(maxplayerscore) playerscore.remove(minplayerscore) avgscore = sum(playerscore) / len(playerscore) chosenone=max(avgscore) print(chosenone)
时间: 2024-03-02 12:51:03 浏览: 64
这段代码中有语法错误,需要先对代码进行修正。以下是修正后的代码:
```python
with open('./score.txt', 'r') as f:
lines = f.readlines()
scores = []
for line in lines:
scorelist = line.strip().split(',')[1:]
scoreint = [int(score) for score in scorelist]
scores.append(scoreint)
avgscores = []
for i in range(3):
playerscore = []
for grade in scores:
playerscore.append(grade[i])
maxplayerscore = max(playerscore)
minplayerscore = min(playerscore)
playerscore.remove(maxplayerscore)
playerscore.remove(minplayerscore)
avgscore = sum(playerscore) / len(playerscore)
avgscores.append(avgscore)
chosenone = max(avgscores)
print(chosenone)
```
这段代码从文件中读取学生成绩,计算每门课程的平均分,然后输出平均分最高的课程的平均分。
阅读全文