+ 1
How do i solve this problem from code coach?
This is the question: 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] This the code I've written: x = int(input()) #your code goes here o = [i for i in range(x) if x%15 == 0] print(o) But this code is printing an empty list. How to fix this? Pls help.
6 Answers
+ 6
Aditya , should be i % 15 == 0, instead of x % 15 == 0. Look at the code.
https://code.sololearn.com/caUdB22NbDSz/?ref=app
+ 5
correct
x = int(input())
under = [i for i in range(x) if i % 5 ==0 and i % 3==0]
print(under)
+ 1
Thank you so much THEWHITECAT
+ 1
Aditya , you are welcome đ±
+ 1
x = int(input())
#your code goes here
list=[i for i in range(x) if i % 15 == 0]
print(list)
0
Question:
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]
Solution:
x = int(input()) #1.Get integer input from user
allnos=[15*i for i in range(50) if 15*i<x] #Multiples of 3 AND 5 are multiples if 15
print(allnos) #printing comprehension