0

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.

15th Sep 2020, 6:06 PM
Vasyl Makoviychuk
7 Answers
+ 6
print([i for i in range(0,42,15)])
15th Sep 2020, 6:28 PM
Oma Falk
Oma Falk - avatar
+ 6
print([i for i in range(int(input())) if i%3==0 and i%5==0])
15th Sep 2020, 6:29 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
Lis=[] for i in range(42): if i%5==0 and i%3==0: Lis.append(i)
15th Sep 2020, 6:10 PM
Ajith
Ajith - avatar
+ 5
Jan Markus lazy...I am simply lazy
15th Sep 2020, 6:32 PM
Oma Falk
Oma Falk - avatar
+ 3
Thank you very much for your help!
15th Sep 2020, 6:22 PM
Vasyl Makoviychuk
+ 1
print([i for i in range(42) if i%15 == 0])....Single line program
17th Sep 2020, 6:00 PM
Karmakar Sunita
Karmakar Sunita - avatar
0
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)
14th Aug 2021, 4:34 AM
Winston Rodricks
Winston Rodricks - avatar