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]
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)
+ 2
Koral Q i posted my attempt
+ 2
NotAPythonNinja thanks dude, it seems like i left out the i before ‘for’
+ 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
+ 2
Koral Q i did it a different way, it works the same
https://code.sololearn.com/cOtAXg0gqGxQ/?ref=app
+ 1
Check this out fella!
https://code.sololearn.com/cVYgsflRyQ7D/?ref=app
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)
0
Here is my solution:
x = int(input())
result = [i for i in range(x) if i % 15 == 0]
print(result)
0
n = int(input())
N = range(12)
x = [n*2**i for i in N]
print(x)
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)