用pythom生成设计一个程序为参加歌手大赛的选手计算最终得分。评委给出的分数是 0~10 分。选手最后得分:去掉一个最高分,去掉一个最低分,计算其余评委打分的平均值。
时间: 2024-06-13 18:06:47 浏览: 11
以下是Python程序,用于计算参加歌手大赛的选手的最终得分:
```python
scores = [] # 评委打分列表
for i in range(5): # 假设有5个评委
score = float(input("请输入第%d个评委的打分:" % (i+1)))
while score < 0 or score > 10: # 判断输入是否合法
score = float(input("输入不合法,请重新输入第%d个评委的打分:" % (i+1)))
scores.append(score)
scores.sort() # 排序
scores = scores[1:-1] # 去掉一个最高分和一个最低分
avg_score = sum(scores) / len(scores) # 计算平均分
print("最终得分为:%.2f" % 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))
```
该程序首先使用一个for循环来获取5位评委的分数,并使用while循环确保输入的分数在0至10之间。然后,程序计算去掉一个最高分和一个最低分后的平均分,并将结果输出。
相关推荐
![](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)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)