用字典统计Tom Marry和q的语文,数学,英语成绩,并计算Tom和Marry的语文,数学,英语总分,并显示总人数,统计Tom Marry和q的语文,数学,英语的平均分
时间: 2023-05-27 17:08:00 浏览: 120
成绩统计求平均分,并输出第一名信息
scores = {
'Tom': {'语文': 90, '数学': 80, '英语': 85},
'Marry': {'语文': 95, '数学': 75, '英语': 90},
'q': {'语文': 85, '数学': 90, '英语': 80}
}
# 统计Tom和Marry的语文,数学,英语总分
Tom_total = sum(scores['Tom'].values())
Marry_total = sum(scores['Marry'].values())
# 显示总人数
total_students = len(scores)
# 统计Tom Marry和q的语文,数学,英语的平均分
Chinese_avg = (scores['Tom']['语文'] + scores['Marry']['语文'] + scores['q']['语文']) / total_students
Math_avg = (scores['Tom']['数学'] + scores['Marry']['数学'] + scores['q']['数学']) / total_students
English_avg = (scores['Tom']['英语'] + scores['Marry']['英语'] + scores['q']['英语']) / total_students
print('Tom的总分为:', Tom_total)
print('Marry的总分为:', Marry_total)
print('总人数为:', total_students)
print('语文的平均分为:', Chinese_avg)
print('数学的平均分为:', Math_avg)
print('英语的平均分为:', English_avg)
阅读全文