有一个班4个学生,5门课程。\n\n求第2个学生5门课程的平均成绩;\n\n求第1门课程的平均分;\n\n找出有一门以上课程不及格的学生,输出他们是第几个学生及每个学生的所有课程成绩。\n\n分别用3个函数实现以上要
时间: 2023-03-16 17:45:54 浏览: 71
求第2个学生5门课程的平均成绩:
定义一个函数,输入班级成绩列表,输出第2个学生5门课程的平均成绩。
def avg_score_of_second_student(scores):
second_student_scores = scores[1]
avg_score = sum(second_student_scores) / len(second_student_scores)
return avg_score
求第1门课程的平均分:
定义一个函数,输入班级成绩列表,输出第1门课程的平均分。
def avg_score_of_first_course(scores):
first_course_scores = [score[] for score in scores]
avg_score = sum(first_course_scores) / len(first_course_scores)
return avg_score
找出有一门以上课程不及格的学生,输出他们是第几个学生及每个学生的所有课程成绩:
定义一个函数,输入班级成绩列表,输出有一门以上课程不及格的学生及每个学生的所有课程成绩。
def find_failed_students(scores):
failed_students = []
for i, student_scores in enumerate(scores):
if any(score < 60 for score in student_scores):
failed_students.append((i+1, student_scores))
return failed_students
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)