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 [5]:
numbers = [] # create an empty list to store all my numbers in
for i in range(1000): #this give me i values from 0 to 999
if i % 3 == 0 or i % 5 == 0: # if i divided by 3 or 5 yields a remainder of 0
numbers.append(i) # then that number is a multiple of 3 or 5 and is added to the list 'numbers'
answer = sum(numbers) # let the variable 'answer' equal the sum of the numbers in 'numbers'
print(answer) # and finally print the answer
In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.