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.
7 Réponses
+ 6
print([i for i in range(0,42,15)])
+ 6
print([i for i in range(int(input())) if i%3==0 and i%5==0])
+ 5
Lis=[]
for i in range(42):
if i%5==0 and i%3==0:
Lis.append(i)
+ 5
Jan Markus lazy...I am simply lazy
+ 3
Thank you very much for your help!
+ 1
print([i for i in range(42) if i%15 == 0])....Single line program
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)