python
时间: 2023-06-22 17:30:57 浏览: 70
python是个什么东西---python---pyqt做的一个浏览器
好的,以下是针对你的问题的 Python 代码实现:
```python
# 定义1班学生的成绩单
scores = {
'小明': {'语文': 90, '数学': 70, '英语': 85},
'小红': {'语文': 80, '数学': 90, '英语': 95},
'小刚': {'语文': 70, '数学': 60, '英语': 75}
}
# 遍历输出1班学生的成绩单
for name, score in scores.items():
print(name, score)
# 求出每个学生的总成绩后加到原有字典中然后打印每个学生信息
for name, score in scores.items():
total_score = sum(score.values())
score['总成绩'] = total_score
print(name, score)
# 求出每门课的平均成绩并输出
scores_list = list(scores.values())
chinese_scores = [stu_scores['语文'] for stu_scores in scores_list]
math_scores = [stu_scores['数学'] for stu_scores in scores_list]
english_scores = [stu_scores['英语'] for stu_scores in scores_list]
chinese_avg = sum(chinese_scores) / len(chinese_scores)
math_avg = sum(math_scores) / len(math_scores)
english_avg = sum(english_scores) / len(english_scores)
print('语文平均成绩为:', chinese_avg)
print('数学平均成绩为:', math_avg)
print('英语平均成绩为:', english_avg)
# 找出数学低于平均分的学生,打印他们的姓名,班级,数学成绩
math_avg = sum(math_scores) / len(math_scores)
for name, score in scores.items():
if score['数学'] < math_avg:
print('姓名:', name, '班级:1班', '数学成绩:', score['数学'])
```
希望这个代码能够帮助你解决问题!
阅读全文