设有3个学生,4门功课,编写2个函数分别实现如下功能:+(1)求每个学生的平均分;+(2)+找出一门以上课程不及格的学生
时间: 2024-06-14 13:04:01 浏览: 101
以下是两个函数实现你所需的功能:
1. 求每个学生的平均分
```python
def calculate_avg(scores):
avg_scores = []
for student_scores in scores:
avg_score = sum(student_scores) / len(student_scores)
avg_scores.append(avg_score)
return avg_scores
# 示例数据
scores = [[80, 90, 85, 95], [70, 60, 75, 80], [90, 85, 80, 95]]
student_avgs = calculate_avg(scores)
print(student_avgs) # 输出:[87.5, 71.25, 87.5]
```
2. 找出一门以上课程不及格的学生
```python
def find_fail_students(scores):
fail_students = []
for i, student_scores in enumerate(scores):
if len([score for score in student_scores if score < 60]) >= 1:
fail_students.append(i + 1)
return fail_students
# 示例数据
scores = [[80, 90, 85, 95], [70, 60, 75, 80], [90, 85, 80, 95]]
fail_students = find_fail_students(scores)
print(fail_students) # 输出:[2]
```
阅读全文