有5个学生每个学生的数据包括学号姓名3门课的成绩。从键盘输人5个学生数据,要求输出3门课总平均成绩,以及最高分的学生的数据(包括学号、姓名,3门课的成绩、平均分数)。本题是第9章第5题。
时间: 2024-01-06 09:06:55 浏览: 116
以下是根据提供的引用内容给出的答案:
```python
# 输入学生数据
students = []
for i in range(5):
student = {}
student['学号'] = input("请输入学号:")
student['姓名'] = input("请输入姓名:")
student['成绩1'] = float(input("请输入第一门课程成绩:"))
student['成绩2'] = float(input("请输入第二门课程成绩:"))
student['成绩3'] = float(input("请输入第三门课程成绩:"))
students.append(student)
# 计算总平均成绩
total_avg = 0
for student in students:
total_avg += (student['成绩1'] + student['成绩2'] + student['成绩3']) / 3
total_avg /= len(students)
# 找到最高分的学生
max_score = 0
max_student = {}
for student in students:
avg_score = (student['成绩1'] + student['成绩2'] + student['成绩3']) / 3
if avg_score > max_score:
max_score = avg_score
max_student = student
# 输出结果
print("3门课总平均成绩:", total_avg)
print("最高分的学生数据:")
print("学号:", max_student['学号'])
print("姓名:", max_student['姓名'])
print("成绩1:", max_student['成绩1'])
print("成绩2:", max_student['成绩2'])
print("成绩3:", max_student['成绩3'])
print("平均分数:", max_score)
```
阅读全文