0

List comprehension - need help!!

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]

18th Oct 2020, 3:31 PM
Greezy gree
Greezy gree - avatar
10 odpowiedzi
+ 5
x = int(input()) #your code goes here lista = [i for i in range(x) if i%3==0 and i%5==0] print(lista)
27th Jun 2021, 11:55 AM
Mohamed Ikram Ifham
Mohamed Ikram Ifham - avatar
+ 2
Koral Q i posted my attempt
18th Oct 2020, 3:35 PM
Greezy gree
Greezy gree - avatar
+ 2
NotAPythonNinja thanks dude, it seems like i left out the i before ‘for’
18th Oct 2020, 3:43 PM
Greezy gree
Greezy gree - avatar
+ 2
ok sorry I didn't notice since I am using solo web.The problem is in your third line list = [for i in range(x) if i % 3 == 0 and i%5 == 0] I am not sure as I am not expert in py but I think you cannot write like this as for loop doesn't return anything also you are not using list's function to take input.You should use append function to get the value from the condition. your code should be something like that: https://code.sololearn.com/cJuFhB7HxLLA
18th Oct 2020, 3:46 PM
The future is now thanks to science
The future is now thanks to science - avatar
+ 2
Koral Q i did it a different way, it works the same https://code.sololearn.com/cOtAXg0gqGxQ/?ref=app
18th Oct 2020, 3:53 PM
Greezy gree
Greezy gree - avatar
18th Oct 2020, 4:03 PM
Shadoff
Shadoff - avatar
0
heres what i tried x = int(input()) #your code goes here list = [for i in range(x) if i % 3 == 0 and i%5 == 0] print(list)
18th Oct 2020, 3:33 PM
Greezy gree
Greezy gree - avatar
0
Here is my solution: x = int(input()) result = [i for i in range(x) if i % 15 == 0] print(result)
15th Jul 2021, 1:31 AM
Attila
Attila - avatar
0
n = int(input()) N = range(12) x = [n*2**i for i in N] print(x)
10th Sep 2021, 10:17 AM
Rayen Boussayed Mohammed Amin
Rayen Boussayed Mohammed Amin - avatar
0
x = int(input()) #your code goes here nums =[ x for x in range (x) if x % 3 ==0 and x % 5 == 0] print (nums)
6th Jul 2022, 6:16 AM
Zocimo Orozco Valencia