+ 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!!!!
9 Respuestas
+ 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)
+ 2
There will be needed an array with these numbers as output.
+ 2
thank you so much for the help guys. Its was confusing but just adding a 1 helped XD
+ 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)
+ 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.
0
plz answe sir
- 1
haha
- 1
answer 4