请编写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} } 请按要求分别完成以下任务: (1)计算这几位同学的语文和数学成绩的平均分(保留1位小数)并输出。 (2)找出两门课都不及格(<60)的学生,并按照字母表从A至Z的顺序逐一输出他们的姓名。 (3)找出两门课的平均分在90分以上(>90)的学生,并按照字母表从A至Z的顺序逐一输出他们的姓名。 输入格式: 无输入 输出格式: 每个任务的输出结果分别占1行,请直接拷贝输出样例的文字到程序中使用 输入样例: 无 输出样例: The Chinese average score is 88.8 The Math average score is 88.8 Students failed in both courses are:Jack,Tom,…… Students with average scores of more than 90 in the two courses are:Jack,Tom,……
时间: 2023-06-19 16:05:38 浏览: 203
```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}
}
# (1) 计算语文和数学成绩的平均分
chinese_scores = []
math_scores = []
for name, scores_dict in scores.items():
chinese_scores.append(scores_dict['Chinese'])
math_scores.append(scores_dict['Math'])
chinese_avg = round(sum(chinese_scores) / len(chinese_scores), 1)
math_avg = round(sum(math_scores) / len(math_scores), 1)
print(f"The Chinese average score is {chinese_avg}")
print(f"The Math average score is {math_avg}")
# (2) 找出两门课都不及格的学生
failed_students = []
for name, scores_dict in scores.items():
if scores_dict['Chinese'] < 60 and scores_dict['Math'] < 60:
failed_students.append(name)
failed_students.sort()
print("Students failed in both courses are:" + ",".join(failed_students))
# (3) 找出两门课的平均分在90分以上的学生
top_students = []
for name, scores_dict in scores.items():
if sum(scores_dict.values()) / len(scores_dict) > 90:
top_students.append(name)
top_students.sort()
print("Students with average scores of more than 90 in the two courses are:" + ",".join(top_students))
```
阅读全文
相关推荐



















