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.
14 Réponses
+ 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)
+ 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.
+ 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.
+ 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
+ 1
@ Ipang: Tried that too, even without zero(0), it remains unaccepted. Thanks anyways
@ AJ.Anant: its a 'code coach' challenge
+ 1
0 is not a multiple of 5 and 3 🙃🙃🙃
+ 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)
0
Shanjul Shrivastava
Can you tell which practice section it is so I can tell where is mistake.
0
@ Ipang: Tried that too, even without zero(0), it remains unaccepted. Thanks anyways
@ AJ.Anant: its a 'code coach' challenge
0
Shanjul Shrivastava
In Code Coach Challenge I found this challenge but here description is different.
https://www.sololearn.com/coach/89?ref=app
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) ])
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
0
import numpy as np
x = np.arange(1, 100)
print(x[(x%3==0) & (x%5==0)])
0
import numpy as np
x = np.arange(1,100)
print(x[(x%3==0)&(x%5==0)])