使用 python 求 3 或 5 但不是 15 的倍数

问题描述 投票:0回答:1

我想在 python 中找到 3 和 5 而不是 15 的倍数

** 但使用列表理解

列表 = []

a = [a for a in range(1,100) if ((a % 3 == 0) and (a % 5 == 0))] 列表.append(a) 打印(一)

****这是错误的逻辑

python list-comprehension
1个回答
0
投票

multiples = [num for num in range(1, 100) if ((num % 3 == 0) or (num % 5 == 0)) and (num % 15 != 0)] 打印(倍数)

© www.soinside.com 2019 - 2024. All rights reserved.