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.

Recommended Answers

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

Jump to Post

All 2 Replies

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

Oh, of coruse. Thanks again, I think I've got it from here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.