+ 2

Index & Slicing python data science course practice

Multiples of 3 & 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. Here is my code import numpy as np x = np.arange(100) nums = x[(x%3==0) & (x%5==0)] for num in nums: print(num) The output is 0 15 30 45 60 75 90 But they still says that I am wrong. Please help!!!!

11th Apr 2021, 4:50 AM
Alvin Nguyen
Alvin Nguyen - avatar
9 Answers
+ 2
Alvin Nguyen There are 2 things 1 - You should not include 0 because it is divisible by any number. So do x = np.arange(1, 100) 2 - You should not print each value in separate lines so just do print(nums) Finally complete solution: import numpy as np x = np.arange(1, 100) nums = x[(x % 3 == 0) & (x % 5 == 0)] print(nums)
11th Apr 2021, 5:36 AM
A͢J
A͢J - avatar
+ 2
There will be needed an array with these numbers as output.
11th Apr 2021, 5:46 AM
JaScript
JaScript - avatar
+ 2
thank you so much for the help guys. Its was confusing but just adding a 1 helped XD
11th Apr 2021, 7:16 AM
Alvin Nguyen
Alvin Nguyen - avatar
+ 2
nums=[] for i in range(1,100): if(i%3==0 and i%5==0): nums.append(i) print(nums) or nums=[i for i in range(1,100) if (i%3==0 and i%5==0)] print(nums)
15th Apr 2021, 9:07 AM
hellouser
+ 1
x = np.arange(1,100) well, the confusion arises as we include zero as well which is a common multiple for all. I solved this using 1 as starting value, but this can be solved using any 0 < num <= 15 I hope that clears your confusion.
11th Apr 2021, 5:05 AM
CHANDAN ROY
CHANDAN ROY - avatar
0
plz answe sir
18th Dec 2022, 6:12 AM
DESAM YASHODA
DESAM YASHODA - avatar
- 1
haha
7th May 2021, 5:40 AM
Cholo Gambol
Cholo Gambol - avatar
- 1
answer 4
6th May 2022, 8:33 AM
Jahongir Sirojiddinov
Jahongir Sirojiddinov - avatar