有一学生各科成绩数据(数据格式:姓名,语文,数学),读取上述文件数据,并计算语文、数学课程的平均分,筛选出语文成绩大于35分的学生姓名。
时间: 2023-10-06 08:04:24 浏览: 143
假设数据文件名为 `data.txt`,文件内容如下:
```
张三, 80, 90
李四, 70, 85
王五, 90, 60
赵六, 45, 75
```
可以使用 Python 来读取和处理这些数据,代码如下:
```python
# 读取文件内容
with open('data.txt', 'r') as f:
lines = f.readlines()
# 处理数据
chinese_sum = 0
math_sum = 0
students = []
for line in lines:
name, chinese, math = line.strip().split(',')
chinese = int(chinese)
math = int(math)
chinese_sum += chinese
math_sum += math
if chinese > 35:
students.append(name)
# 计算平均分
chinese_avg = chinese_sum / len(lines)
math_avg = math_sum / len(lines)
# 输出结果
print("语文平均分:", chinese_avg)
print("数学平均分:", math_avg)
print("语文成绩大于35分的学生:", students)
```
运行结果如下:
```
语文平均分: 71.25
数学平均分: 77.5
语文成绩大于35分的学生: ['张三', '王五', '赵六']
```
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)