1.传统方法
1 from random import randint 2 3 chinese = [randint(60, 100) for _ in range(40)] 4 math = [randint(60, 100) for _ in range(40)] 5 english= [randint(60, 100) for _ in range(40)] 6 7 8 for i in range(len(math)): 9 sum = chinese[i] + math[i] + english[i] 10 print(sum)
2.zip实现
1 from random import randint 2 3 chinese = [randint(60, 100) for _ in range(40)] 4 math = [randint(60, 100) for _ in range(40)] 5 english= [randint(60, 100) for _ in range(40)] 6 7 8 total = [] 9 for c, m, e in zip(chinese, math, english): 10 total.append(c+m+e) 11 12 print(total)
3. chain实现
from itertools import chain c1 = [randint(60, 100) for _ in range(40)] c2 = [randint(60, 100) for _ in range(42)] c3 = [randint(60, 100) for _ in range(42)] c4 = [randint(60, 100) for _ in range(39)] count = 0 for s in chain(c1, c2, c3, c4): if s > 90: count += 1 print(count)