a = [4, 5, 3, 6, 7, 8, 9]
count = 0
for i in a:
if i == 1 or i == 2 or i == 3 or i == 4 or i == 5 or i == 0:
count += I
print(count)
我尝试过以下一行代码,但是不起作用:
print(sum(i) if (i == 1 or i == 2 or i == 3 or i == 4 or i == 5 or i == 0) for i in a)
print(sum([x for x in a if x < 6]))