📅  最后修改于: 2023-12-03 15:06:10.818000             🧑  作者: Mango
这个程序可以根据输入的学生信息,计算每个学生的三科平均分,然后找出三科平均分最高的学生。
def find_highest_avg_score(students):
highest_avg_score = 0
highest_avg_score_students = []
for student in students:
name = student['name']
chinese_score = student['chinese']
math_score = student['math']
english_score = student['english']
avg_score = (chinese_score + math_score + english_score) / 3
student['avg_score'] = avg_score
if avg_score > highest_avg_score:
highest_avg_score = avg_score
highest_avg_score_students = [name]
elif avg_score == highest_avg_score:
highest_avg_score_students.append(name)
print("每个学生的三科平均分:")
for student in students:
print("{}的平均分是{}".format(student['name'], student['avg_score']))
print("\n三科平均分最高的学生:")
for name in highest_avg_score_students:
print("{}的平均分是{}".format(name, highest_avg_score))
students = [
{'name': '张三', 'chinese': 80, 'math': 90, 'english': 70},
{'name': '李四', 'chinese': 90, 'math': 85, 'english': 80},
{'name': '王五', 'chinese': 70, 'math': 70, 'english': 80},
{'name': '赵六', 'chinese': 80, 'math': 90, 'english': 90},
{'name': '钱七', 'chinese': 80, 'math': 80, 'english': 80},
]
find_highest_avg_score(students)
每个学生的三科平均分:
张三的平均分是80.0
李四的平均分是85.0
王五的平均分是73.33333333333333
赵六的平均分是86.66666666666667
钱七的平均分是80.0
三科平均分最高的学生:
赵六的平均分是86.66666666666667