w3resource

Python Challenges: Compute the sum of all the multiples of 3 or 5 below 500

Python Challenges - 1: Exercise-33 with Solution

Write a Python program to compute the sum of all the multiples of 3 or 5 below 500.

All the natural numbers below 12 that are multiples of 3 or 5, we get 3, 5, 6, 9 and 10. The sum of these multiples is 33.

Sample Solution:

Python Code:

n = 0
for i in range(1,500):
     if not i % 5 or not i % 3:
         n = n + i
print(n)

Sample Output:

57918

Flowchart:

Python Flowchart: Compute the sum of all the multiples of 3 or 5 below 500

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to find the single number which occurs odd numbers and other numbers occur even number.
Next: Write a Python program to compute the sum of the even-valued terms in the Fibonacci sequence whose values do not exceed one million.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/challenges/1/python-challenges-1-exercise-33.php