题目: 有一个班4个学生, 5门课程。 ①求第1门课程的平均分; ②找出有两门以上课程不及格的学生, 输出他们的学号和全部课程成绩及平均成绩; ③找出平均成绩在90分以上或全部课程成绩在85分以上的学生。 分别编3个函数实现以上3个要求。
时间: 2024-02-24 16:58:10 浏览: 180
好的,我来回答你的问题。
1. 求第1门课程的平均分的函数:
```python
def average_score(course_scores, course_num):
# course_scores是一个二维列表,存储了4个学生5门课的成绩
# course_num是要求平均分的课程编号,从1开始
total_score = 0
for i in range(len(course_scores)):
total_score += course_scores[i][course_num-1]
return total_score / len(course_scores)
```
2. 找出有两门以上课程不及格的学生的函数:
```python
def failed_students(course_scores):
# course_scores是一个二维列表,存储了4个学生5门课的成绩
failed_students = []
for i in range(len(course_scores)):
failed_num = 0
total_score = 0
for j in range(len(course_scores[i])):
if course_scores[i][j] < 60:
failed_num += 1
total_score += course_scores[i][j]
if failed_num >= 2:
avg_score = total_score / len(course_scores[i])
student_info = {'学号': i+1, '全部成绩': course_scores[i], '平均成绩': avg_score}
failed_students.append(student_info)
return failed_students
```
3. 找出平均成绩在90分以上或全部课程成绩在85分以上的学生的函数:
```python
def excellent_students(course_scores):
# course_scores是一个二维列表,存储了4个学生5门课的成绩
excellent_students = []
for i in range(len(course_scores)):
total_score = 0
avg_score = 0
all_above_85 = True
for j in range(len(course_scores[i])):
if course_scores[i][j] < 85:
all_above_85 = False
total_score += course_scores[i][j]
avg_score = total_score / len(course_scores[i])
if avg_score >= 90 or all_above_85:
student_info = {'学号': i+1, '全部成绩': course_scores[i], '平均成绩': avg_score}
excellent_students.append(student_info)
return excellent_students
```
希望能够帮到你!
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044937.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.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)
![](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)