输入全班10名同学的姓名和成绩,输出全班的总成绩、平均成绩以及获得最高成绩和最低成绩的同学要求利用字典实现 用python编写程序
时间: 2023-09-06 12:09:45 浏览: 88
好的,我可以帮你编写这个程序。以下是代码:
```python
scores = {}
total_score = 0
highest_score = 0
lowest_score = float('inf')
# 输入同学姓名和成绩
for i in range(10):
name = input("请输入第{}名同学的姓名:".format(i+1))
score = float(input("请输入第{}名同学的成绩:".format(i+1)))
scores[name] = score
total_score += score
if score > highest_score:
highest_score = score
highest_student = name
if score < lowest_score:
lowest_score = score
lowest_student = name
# 计算平均成绩
average_score = total_score / 10
# 输出结果
print("全班总成绩为:{}".format(total_score))
print("全班平均成绩为:{}".format(average_score))
print("获得最高成绩的同学是{},成绩为{}".format(highest_student, highest_score))
print("获得最低成绩的同学是{},成绩为{}".format(lowest_student, lowest_score))
```
程序运行时,会依次输入每个同学的姓名和成绩,然后计算全班的总成绩、平均成绩以及获得最高成绩和最低成绩的同学,并输出结果。注意,这里使用了字典来存储每个同学的姓名和成绩,方便后续的处理。