List comprehension | Sololearn: Learn to code for FREE!


List comprehension

Hi! I can't resolve this exercise: Write a program to take a number as input, and output a list of all the numbers below that number, that are a multiple of both, 3 and 5. Sample Input 42 Sample Output [0, 15, 30] I understand that I should do it alone, but I am already desperate enough. At least I ask for a hint.

9/15/2020 6:06:24 PM

Vasyl Makoviychuk

7 Answers

New Answer


print([i for i in range(0,42,15)])


print([i for i in range(int(input())) if i%3==0 and i%5==0])


Lis=[] for i in range(42): if i%5==0 and i%3==0: Lis.append(i)


Jan Markus lazy...I am simply lazy


Thank you very much for your help!


print([i for i in range(42) if i%15 == 0])....Single line program


I found this to solve the problem x=int(input) num = [j for j in range(0,x) if ((not j%3) and (not j%5))] print(num)