Project Euler: Problem 1

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 [9]:
sum_of_multiples=0

for i in range (0,1000):
    if i%3==0 or i%5==0:
        sum_of_multiples = sum_of_multiples + i

print (sum_of_multiples)


233168

I set sum_of_multiples equal to zero in order to start my sum at zero. I then used a for loop to loop through all the numbers in the range 0-1000. Then used an if statement, if a number in this range is evenly divisible by three or evenly divisble by 5 add that number to the sum_of_multiples. Then I printed the final sum_of_multiples.


In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.