# 声明一个数字列表
nums = [12, 10, 32, 3, 66, 17, 42, 99, 20]

# 声明新变量
newlist = []

# 遍历nums并将数字添加到newlist中
for i in nums:
    if i % 2 == 0:
        newlist.append(i)

print(newlist)
简化给定代码。
# 声明一个数字列表
nums = [12, 10, 32, 3, 66, 17, 42, 99, 20]

# 遍历nums并将偶数添加到newlist中
newlist = [i for i in nums if i % 2 == 0]

print(newlist)