公务员面试现场打分。有7位考官,从键盘输入若干组成绩,每组7个分数(百分制),去掉一个最高分和一个最低分,输出每组的平均成绩。
时间: 2023-06-11 07:07:39 浏览: 53
可以使用以下的 Python 代码来实现:
```python
scores = []
for i in range(7):
score = input('请输入第 {} 位考官的成绩(用空格分隔):'.format(i+1))
scores.append(list(map(int, score.split())))
for i in range(len(scores)):
scores[i].sort() # 排序
_sum = sum(scores[i][1:6]) # 去掉最高分和最低分,求和
average = _sum / 5 # 求平均值
print('第 {} 组的平均成绩为:{:.2f}'.format(i+1, average))
```
这段代码使用一个二维列表 `scores` 来存储所有考官的成绩。输入时,依次输入每个考官的成绩,使用 `split()` 方法将输入的字符串转换成整数列表,并将这个列表添加到 `scores` 中。
接下来,对每组成绩进行处理。首先对这组成绩从小到大进行排序,然后去掉最高分和最低分,求剩余分数的总和,并计算平均值。最后输出每组的平均成绩即可。
相关问题
Python公务员面试现场打分。有7位考官,从键盘输入若干组成绩,每组7个分数(百分制),
然后求出每个考生的总分和平均分,并输出所有考生的总分和平均分。
可以使用以下代码实现:
```python
scores = []
while True:
line = input("请输入考生成绩(用逗号分隔):")
if not line:
break
scores.append([int(x) for x in line.split(",")])
total_scores = []
for i in range(len(scores)):
total = sum(scores[i])
avg = total / len(scores[i])
total_scores.append(total)
print("第{}个考生的总分为{},平均分为{:.2f}".format(i+1, total, avg))
avg_total = sum(total_scores) / len(total_scores)
print("所有考生的总分为{},平均分为{:.2f}".format(sum(total_scores), avg_total))
```
这段代码中,我们首先通过一个循环,从键盘输入每个考生的7个分数,将这些分数保存在一个二维列表`scores`中。接着,我们遍历`scores`列表,计算每个考生的总分和平均分,并将总分保存在一个一维列表`total_scores`中。最后,我们再次遍历`total_scores`列表,求出所有考生的总分和平均分,并将结果输出到屏幕上。
python公务员面试现场打分。有7位考官,从键盘输入7个分数(百分制), 去掉一个最高分和一个最低分,输出每组的平均成绩。 如输入:99 45 78 67 72 88 60(一次输入一组,空格分隔) 输出:73.00
这是一个简单的Python编程问题。可以使用列表和sort()函数来实现。
以下是一组代码实现此问题:
```
scores = input().split() # 获取输入的7个分数
scores = [int(score) for score in scores] # 将分数转换为整数类型
scores.sort() # 排序
scores = scores[1:6] # 去掉最高分和最低分
average = sum(scores) / len(scores) # 计算平均成绩
print('%.2f' % average) # 输出平均成绩,保留两位小数
```
对于这个问题,我的回答是:可以使用Python编写程序解决,具体实现方法如上所述。非常简单吧!
相关推荐
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)