输入全班十名同学的姓名和成绩输出全班的总成绩平均成绩以及获得最高成绩和最低成绩的同学要求利用字典实现 用python编写程序
时间: 2023-09-06 18:09:45 浏览: 135
好的,以下是您的需求的 Python 3 代码:
```python
# 创建一个字典,用于存储同学的姓名和成绩
students = {}
# 循环输入同学的姓名和成绩
for i in range(1, 11):
name = input("请输入第{}名同学的姓名:".format(i))
score = float(input("请输入第{}名同学的成绩:".format(i)))
students[name] = score
# 计算全班总成绩和平均成绩
total_score = sum(students.values())
average_score = total_score / len(students)
print("全班总成绩为:{},平均成绩为:{}".format(total_score, average_score))
# 找出获得最高成绩和最低成绩的同学
highest_score_student = max(students, key=students.get)
lowest_score_student = min(students, key=students.get)
print("获得最高成绩的同学为:{},成绩为:{}".format(highest_score_student, students[highest_score_student]))
print("获得最低成绩的同学为:{},成绩为:{}".format(lowest_score_student, students[lowest_score_student]))
```
希望这能帮到您!
阅读全文