有5个学生,每个学生的数据包括学号、姓名、3门课的成绩。从键盘输人5个学生数据,要求输出3门课总平均成绩,以及最高分的学生的数据(包括学号、姓名、3门课的成绩、平均分数。 要求:用三个函数实现
时间: 2024-01-06 14:06:41 浏览: 87
以下是实现你所需功能的Python代码:
```python
def input_data():
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)
return students
def calculate_average(students):
total_scores = [0, 0, 0]
for student in students:
total_scores[0] += student['成绩1']
total_scores[1] += student['成绩2']
total_scores[2] += student['成绩3']
average_scores = [score/5 for score in total_scores]
return average_scores
def find_highest_score(students):
highest_score = 0
highest_student = {}
for student in students:
average_score = (student['成绩1'] + student['成绩2'] + student['成绩3']) / 3
if average_score > highest_score:
highest_score = average_score
highest_student = student
return highest_student
students = input_data()
average_scores = calculate_average(students)
highest_student = find_highest_score(students)
print("3门课的总平均成绩为:", average_scores)
print("最高分的学生数据为:", highest_student)
```
阅读全文