【Python】实现输出成绩最高或最低分的学生姓名以及低于平均分的学生姓名

scores = {"小刘": 45, "小红": 68, "小米": 96, "小白": 65, "小梦": 75}
highest = max(scores.values())
lowest = min(scores.values())
average = sum(scores.values()) / len(scores)
# print("平均值为:"+str(average))
max_keys = [k for k, x in scores.items() if not any(y > x for y in scores.values())]
print('成绩最高的是:')
for student in max_keys:
    print(student)
min_keys = [k for k, x in scores.items() if not any(y < x for y in scores.values())]
print('成绩最低的是:')
for student in min_keys:
    print(student)


personName = [k for k, v in scores.items() if v < average]
print("低于平均值的学生:")
for student in personName:
    print(student)

 

本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/15366940.html

posted @ 2021-10-04 18:46  木子欢儿  阅读(178)  评论(0编辑  收藏  举报