scores={'Tom':{'Chinese':95,'Math':98}, 'Jack':{'Chinese':85,'Math':85}, 'Jerry':{'Chinese':56,'Math':36}, 'Rose':{'Chinese':87,'Math':85}, 'Mary':{'Chinese':97,'Math':95} } 请按要求分别完成以下任务: (1)计算这几位同学的语文和数学成绩的平均分(保留1位小数)并输出。(2)找出两门课都不及格(<60)的学生,并按照字母表从A至Z的顺序逐一输出他们的姓名。(3)找出两门课的平均分在90分以上(>90)的学生,并按照字母表从A至Z的顺序逐一输出他们的姓名。
时间: 2023-06-27 18:05:04 浏览: 249
(1) 计算语文和数学成绩的平均分并输出:
```python
scores = {'Tom':{'Chinese':95,'Math':98},
'Jack':{'Chinese':85,'Math':85},
'Jerry':{'Chinese':56,'Math':36},
'Rose':{'Chinese':87,'Math':85},
'Mary':{'Chinese':97,'Math':95}}
chinese_total = 0
math_total = 0
for name in scores:
chinese_total += scores[name]['Chinese']
math_total += scores[name]['Math']
chinese_avg = round(chinese_total / len(scores), 1)
math_avg = round(math_total / len(scores), 1)
print("语文平均分:", chinese_avg)
print("数学平均分:", math_avg)
```
输出:
```
语文平均分: 84.0
数学平均分: 79.8
```
(2) 找出两门课都不及格的学生并按照字母表顺序输出姓名:
```python
failed_students = []
for name in scores:
if scores[name]['Chinese'] < 60 and scores[name]['Math'] < 60:
failed_students.append(name)
failed_students.sort()
for name in failed_students:
print(name)
```
输出:
```
Jerry
```
(3) 找出两门课的平均分在90分以上的学生,并按照字母表顺序输出姓名:
```python
top_students = []
for name in scores:
avg_score = (scores[name]['Chinese'] + scores[name]['Math']) / 2
if avg_score > 90:
top_students.append(name)
top_students.sort()
for name in top_students:
print(name)
```
输出:
```
Mary
Tom
```
阅读全文
相关推荐


















