Q:

Write a NumPy program (using numpy) to sum of all the multiples of 3 or 5 below 100

0

Write a NumPy program (using numpy) to sum of all the multiples of 3 or 5 below 100.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.arange(1, 100)
# find  multiple of 3 or 5
n= x[(x % 3 == 0) | (x % 5 == 0)]
print(n[:1000])
# print sum the numbers
print(n.sum())

Sample Output:

[ 3  5  6  9 10 12 15 18 20 21 24 25 27 30 33 35 36 39 40 42 45 48 50 5
1 54                                                                   
 55 57 60 63 65 66 69 70 72 75 78 80 81 84 85 87 90 93 95 96 99]       
2318

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now