如何用Python计算学生语文和数学课程的平均分,筛选出语文成绩大于35的学生姓名

学生成绩数据格式为姓名,语文,数学。例:
文件内容:
wangwu 35 56
liuliu 8 34
zhangsan 34 23
lisi 56 23
读取上面文件数据,文件为studentdata.txt

img

计算整个列表的平均值可以实现:


grades = [
    ('wangwu', 35, 56),
    ('liuliu', 8, 34),
    ('zhangsan', 34, 23),
    ('lisi', 56, 23)
]

avg_chinese = sum([chinese for name, chinese, math in grades]) / len(grades)
avg_math = sum([math for name, chinese, math in grades]) / len(grades)

filtered_grades = [(name, chinese, math) for name, chinese, math in grades if chinese > 35]

for name, chinese, math in filtered_grades:
    print(name)