4、设计一个程序为参加歌手大赛的选手计算最终得分。评委给出的分数是 0~10 分。选手最后得分:去掉一个最高分,去掉一个最低分,计算其余评委打分的平均值。
时间: 2024-06-13 08:06:47 浏览: 11
以下是Python程序,用于计算参加歌手大赛的选手的最终得分:
```python
scores = [] # 评委打分列表
while True:
score = input("请输入评委打分(0~10分),输入q结束:")
if score == 'q':
break
score = float(score)
if score < 0 or score > 10:
print("分数不在0~10分之间,请重新输入!")
continue
scores.append(score)
if len(scores) < 3:
print("评委人数不足3人,无法计算最终得分!")
else:
scores.sort()
scores = scores[1:-1] # 去掉一个最高分和一个最低分
avg_score = sum(scores) / len(scores) # 计算其余评委打分的平均值
print("最终得分为:{:.2f}".format(avg_score))
```
相关问题
设计一个程序为参加歌手大赛的选手计算最终得分。评委给出的分数是 0~10 分。选手最后得分:去掉一个最高分,去掉一个最低分,计算其余评委打分的平均值
以下是Python程序,用于计算参加歌手大赛的选手的最终得分:
```python
scores = []
num_judges = int(input("请输入评委人数:"))
for i in range(num_judges):
score = float(input("请输入第{}位评委的分数:".format(i+1)))
scores.append(score)
scores.sort()
scores = scores[1:-1]
average_score = sum(scores) / len(scores)
print("选手的最终得分为:{:.2f}".format(average_score))
```
程序首先要求用户输入评委人数,然后使用循环来获取每个评委的分数,并将其添加到一个列表中。然后,程序对分数列表进行排序,并去掉最高分和最低分。最后,程序计算剩余分数的平均值,并将其输出作为选手的最终得分。
python设计一个程序为参加歌手大赛的选手计算最终得分。评委给出的分数是 0~10 分。选手最后得分:去掉一个最高分,去掉一个最低分,计算其余评委打分的平均值。
以下是一个Python程序,用于计算参加歌手大赛的选手的最终得分:
```python
scores = []
for i in range(5):
while True:
score = float(input('请输入第{}位评委的分数:'.format(i+1)))
if score < 0 or score > 10:
print('请输入一个0至10的分数')
else:
break
scores.append(score)
average = (sum(scores) - max(scores) - min(scores)) / (len(scores) - 2)
print('歌手最终得分:{:.2f}'.format(average))
```
该程序首先使用一个循环来获取5位评委的分数,并确保分数在0到10之间。然后,它计算除去一个最高分和一个最低分后的平均分数,并将其打印出来。
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)