MST

星途 面试题库

面试题:Python中if语句的逻辑嵌套问题

假设有一个列表,其中包含一些整数。请使用Python的if语句,判断列表中的每个数,如果这个数大于10且小于20,并且这个数是偶数,就将其乘以2,最后输出处理后的列表。请写出完整代码。
40.3万 热度难度
编程语言Python

知识考点

AI 面试

面试题答案

一键面试
my_list = [5, 12, 15, 18, 25]
new_list = []
for num in my_list:
    if 10 < num < 20 and num % 2 == 0:
        new_list.append(num * 2)
    else:
        new_list.append(num)
print(new_list)