PTA的Python练习题-第4章-7 统计学生平均成绩与及格人数
Posted Ch0bits
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PTA的Python练习题-第4章-7 统计学生平均成绩与及格人数相关的知识,希望对你有一定的参考价值。
第4章-7 统计学生平均成绩与及格人数
a=eval(input()) b=list(map(int,input().split())) sum=sum(b) c=[i for i in b if i>=60] count=len(c) print(\'average = %.1f\'%(sum/a)) print(\'count = %d\'%(count))
如果这里用append输入只能实现一行一行输入,不能实现同一行输入
知识点(列表的操作):
""" ①实现嵌套列表的平铺 """
vec = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
""" 第一个循环为外循环,第二个循环为内循环 """
print([num for elem in vec for num in elem])
print(list(chain(*vec)))
""" 过滤不符合条件的元素 """
alist = [-1, -4, 6, 7.5, -2.3, 9, -11]
print([i for i in alist if i > 0])
scores={"Zhang San":45, "Li Si":78, "Wang Wu":40, "Zhou Liu":96,
"Zhao Qi":65, "Sun Ba":90, "Zheng Jiu":78, "Wu Shi":99,
"Dong Shiyi":60}
highest = max(scores.values())
lowest = min(scores.values())
average = sum(scores.values())/len(scores)
print((highest, lowest, average))
highestPerson = [name for name, score in scores.items() if score == highest]
print(highestPerson)
from random import randint
x = [randint(1, 10) for i in range(20)]
print(x)
m = max(x