Find all multiples of 3 or 5 but not 15 using python

Question:

I want to find the multiples of 3 and 5 but not 15, in python
by using list comprehension,

list = []

a = [a for a in range(1,100) if ((a % 3 == 0) and (a % 5 == 0))]
list.append(a)
print(a)

the logic is wrong

Asked By: Harsha A

||

Answers:

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

Answered By: charlessssss
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.