1. 基础题
1.已知一个数字列表,打印列表中所有的奇数
list = [1, 3, 6, 7, 9, 20, 10, 17, 60]
result = [i for i in list if i % 2 != 0]
print(result)
2.已知一个数字列表,打印列表中所有能被能被3整除但是不能被2整除的数
list = [1, 3, 6, 7, 9, 20, 10, 17, 60]
result = [i for i in list if i % 2 != 0 and i % 3 == 0]
print(result)
3.已知一个数字列表,计算所有偶数的和
list = [1, 3, 6, 7, 9, 20]
result = [i for i in list if i % 2 == 0]
print(sum(result))