有10个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学 生数据,要求输出3门课程总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课程成绩、平均分数)
时间: 2025-06-22 13:37:06 浏览: 12
首先,我们需要创建一个结构体或者类来存储每个学生的信息,包含学号、姓名和三门课程的成绩。然后编写一个程序来接收用户的输入,并将其存储到数组或列表中。接着,我们计算所有学生的每门课程总平均成绩,以及找出最高分学生的详细信息。
以下是伪代码的一个简要描述:
```python
# 定义学生类
class Student:
def __init__(self, id, name):
self.id = id
self.name = name
self.course_scores = [0, 0, 0] # 存储三门课程的成绩
# 接收用户输入并创建学生对象
students = []
for _ in range(10):
id = input("请输入学号:")
name = input("请输入姓名:")
for i in range(3):
score = int(input(f"请输入第{i+1}门课程的成绩:"))
students.append(Student(id, name))
# 计算总平均成绩和最高分学生
total_average_scores = [sum(student.course_scores) / 3 for student in students]
highest_score_student = max(students, key=lambda x: sum(x.course_scores))
# 输出结果
average_scores_str = "课程总平均成绩:{:.2f}".format(total_average_scores[0])
print(average_scores_str)
highest_score_data = {
"学号": highest_score_student.id,
"姓名": highest_score_student.name,
"成绩": highest_score_student.course_scores,
"平均分数": total_average_scores[highest_score_student.index],
}
print("最高分学生数据:", highest_score_data)
阅读全文
相关推荐


















