Skip to main content
2 of 2
Markdown code format
janos
  • 111.7k
  • 15
  • 152
  • 391

I used a slightly simpler method, but essentially did the same thing:

total = 0

for n in range(3,1000):
    if n % 3 == 0:
        total += n
    elif n % 5 == 0:
        total += n


print total

The elif makes sure that you only count any factor/divisor once.