Skip to main content
Markdown code format
Source Link
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 elifelif makes sure that you only count any factor/divisor once.

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.

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.

Source Link

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.