#### Python Euler Practice

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.

Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.

Note: If the number is a multiple of both 3 and 5, only count it once. Also, if a number is negative, return 0(for languages that do have them)

``````def solution(number):
sum = 0
if(number <= 0):
return 0
else:
for i in range(1,number+1):
if( i % 3 == 0 or i % 5 == 0 and i % 15 != 0 ):
sum += i
return sum
``````

There are 105 test cases for this challenge in codewars, 55 of them passes and 50 of them don’t. How can I improve my code?

p.s : I do not see which cases pass or which are do not.

p.s 2 : GUYS NOTHING CHANGES WHEN I REMOVE i % 15 != 0

Source: Python Questions

## One Reply to “Python Euler Practice”

• Guo says:

def solution(number):
sum = 0
if(number <= 0):
return 0
else:
for i in range(1,number+1):
if( i % 3 == 0 or i % 5 == 0 and i % 10 != 0 ):
sum += i
return sum