0

Multiples of both 3 and 5

You are given a task to find all of the whole numbers below 100 that are multiples of both 3 and 5. Create an array of numbers below 100 that are multiples of both 3 and 5, and output it. #my approaches: #1st method print([j for j in range(100) if (j % 3 ==0) and (j % 5 ==0)]) #2nd method nums=[] for i in range(100): if(i%3==0 and i%5==0): nums.append(i) print(nums) #Using numpy import numpy as np data = np.arange(100) print([j for j in data if (j % 3 ==0) and (j % 5 ==0)]) Have been able to move formward but still cannot see whats wrong ? Please someone post a working code.

20th May 2021, 2:52 AM
Shanjul Shrivastava
Shanjul Shrivastava - avatar
14 Antworten
+ 4
The following code is accepted, not sure if anything changed at the SoloLearn side. import numpy as np data = np.arange(1, 100) data = data[(data%3 == 0) & (data%5 == 0)] print(data)
24th Jun 2021, 7:17 AM
Maikel
+ 2
A number fully divisible by both 3 and 5 are 15 and its multiples. Have you tried to % by 15? at least it's doing % operation only once, rather than checking % on 3 and 5 for each number. You may also skip % operation by using range() starting from 15, and stepping of 15 also.
20th May 2021, 3:02 AM
Ipang
+ 2
I don't know why either, but maybe you can try to exclude zero from the result list? it wasn't clear whether zero was to be included or not though.
20th May 2021, 3:23 AM
Ipang
+ 1
@Ipang Thanks for the reply. The output i am getting in all 3 approaches is same. i.e. [15, 30, 45, 60, 75, 90]. Don't know why its not getting accepted
20th May 2021, 3:05 AM
Shanjul Shrivastava
Shanjul Shrivastava - avatar
+ 1
@ Ipang: Tried that too, even without zero(0), it remains unaccepted. Thanks anyways @ AJ.Anant: its a 'code coach' challenge
20th May 2021, 6:27 AM
Shanjul Shrivastava
Shanjul Shrivastava - avatar
+ 1
0 is not a multiple of 5 and 3 🙃🙃🙃
26th Jan 2022, 10:34 PM
Hamza Yousfi
Hamza Yousfi - avatar
+ 1
number = int(input()) a = range(0,number,3) a_list = list(a) b = range(0,number,5) b_list = list(b) sum_all_list = sum(set(a_list + b_list)) print(sum_all_list)
16th Jul 2022, 8:40 AM
wqd dqwwdqwd
wqd dqwwdqwd - avatar
0
Shanjul Shrivastava Can you tell which practice section it is so I can tell where is mistake.
20th May 2021, 4:09 AM
A͢J
A͢J - avatar
0
@ Ipang: Tried that too, even without zero(0), it remains unaccepted. Thanks anyways @ AJ.Anant: its a 'code coach' challenge
20th May 2021, 6:28 AM
Shanjul Shrivastava
Shanjul Shrivastava - avatar
0
Shanjul Shrivastava In Code Coach Challenge I found this challenge but here description is different. https://www.sololearn.com/coach/89?ref=app
20th May 2021, 6:41 AM
A͢J
A͢J - avatar
0
I have two bits of code that give exactly the same answer, one gets marked right, one wrong! I find the test cases to be of low quality on this app and why they don't let us see them is beyond me import numpy as np ranger = np.array(range(1,100)) print(ranger[(ranger%3) == 0 & (ranger%5 == 0) ]) X = np.arange(1,100) print(X[(X%3) == 0 & (X%5 == 0) ])
1st May 2022, 8:17 PM
Dave
0
Had this problem as well but figured it out. You should have a np.array as answer, it does not count as the right answer if you have a simple list. Answer [15 30 45 60 75 90] works and [15, 30, 45, 60, 75, 90] doesn't
24th Jun 2022, 7:30 PM
der Verlassenheit
der Verlassenheit - avatar
0
import numpy as np x = np.arange(1, 100) print(x[(x%3==0) & (x%5==0)])
2nd Dec 2022, 5:40 PM
Ronalds Skulme
Ronalds Skulme - avatar
0
import numpy as np x = np.arange(1,100) print(x[(x%3==0)&(x%5==0)])
15th Jan 2023, 2:00 AM
Odoi Yona
Odoi Yona - avatar