第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