If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
In [74]:
#For this problem, I mainly used this site: https://docs.python.org/3/library/functions.html#func-range
#(For the functions that is).
#Step 1: At first, I used x = range() without the set(), but then realized
#there needs to be another function that makes the range
#the data set for x.
x = set(range(0, 1000,3))
y = set(range(0,1000,5))
#Step 2: Adding sets was not as simple as x+y. I used this website to figure out to use ().union()
#Note: this is pretty sweet because there are no repeats within xysum.
# https://docs.python.org/2/library/sets.html
xysum = x.union(y)
#Step 3: Checked xysum. In order to check for xysum, type it at the end.
xysum
#Step 4: I used a simple sum() function here.
Answer = sum(xysum)
#Step 5: Found the answer
Answer
Out[74]:
In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.
In [ ]: