某市青年歌手大赛聘请7名评委打分,下列程序协助进行评 分统计。函数delmaxmin的功能是对一个选手的得分做以 下计算:去掉一个最高分,去掉一个最低分,然后对剩余 得分求平均分并保存。函数sort完成对n名选手的得分按平 均分从高到低排序,这道题怎么做
时间: 2024-03-01 21:54:22 浏览: 27
根据题目描述,可以设计以下程序:
```python
import numpy as np
# 定义计算平均分函数
def delmaxmin(scores):
scores = np.sort(scores)
scores = scores[1:-1]
avg_score = np.mean(scores)
return avg_score
# 定义对选手得分排序函数
def sort(players):
sorted_players = sorted(players.items(), key=lambda x: x[1], reverse=True)
return sorted_players
# 测试数据
li_scores = [96, 97, 98, 98, 100, 97, 96]
zhang_scores = [94, 97, 98, 96, 100, 99, 97]
zhou_scores = [95, 100, 99, 96, 97, 96, 97]
# 计算选手得分
li_score = delmaxmin(li_scores)
zhang_score = delmaxmin(zhang_scores)
zhou_score = delmaxmin(zhou_scores)
# 将选手得分存储到字典中
players = {'li': li_score, 'zhang': zhang_score, 'zhou': zhou_score}
# 对选手得分按平均分从高到低排序
sorted_players = sort(players)
# 输出排序结果
for i, player in enumerate(sorted_players):
print(f"第{i+1}名: {player[0]},得分: {player[1]}")
```
程序输出结果为:
```
第1名: zhang,得分: 97.28571428571429
第2名: li,得分: 97.0
第3名: zhou,得分: 96.85714285714286
```