0

Hey, I tryed the first problem of the Euler project, but for some reason the code bellow is not give me the correct answer:

def multiple_sum(multiple=3):
    x = 0
    for n in range(0, 1000):
        if not (n % multiple):
            x += n
    return x

print multiple_sum(5) + multiple_sum(3)

It is giving me 266333, where it should be giving me 266168
The problem discription is here:

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.

Edit: GOD DAMN THAT RANGE FUNCTION, SHOULD HAVE ADDED ONE TO INCLUDE 1000.

However, this doesn't fix my problem. I'm still hopelessly confused on that front.

Edited by brett.warren.1612

2
Contributors
2
Replies
12
Views
3 Years
Discussion Span
Last Post by brett.warren.1612
0

You're counting all multiples of 15 twice (once as multiples of 3 and once as multiples of 5).

Edited by sepp2k

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.