#coding utf-8
from random import randint
from itertools import chain
# Demo1: get the total scores of each student; score stored in 3 lists(math,chinese,english)
stu_count = 50
math = [randint(60, 100) for x in range(stu_count)]
chinese = [randint(60, 100) for x in range(stu_count)]
english = [randint(60, 100) for x in range(stu_count)]
for m, c, e in zip(math, chinese, english) :
print(m + c + e)
# Demo2: here are 3 lists of students' english scores(en1, en2, en3)
# you need to get the count of score bigger than 90
en1 = [randint(60, 100) for x in range(38)]
en2 = [randint(60, 100) for x in range(40)]
en3 = [randint(60, 100) for x in range(41)]
count = 0
for x in chain(en1, en2, en3) :
if x > 90 :
count += 1
print(count)
Python——for语句中访问可迭代对象
最新推荐文章于 2024-11-11 21:30:41 发布