## (#1) What am I doing wrong?

For questions about problems on the Project Euler web site. No spoilers. Please include the question number in the subject line of your post.

### (#1) What am I doing wrong?

It yields 266,333, which is the wrong answer.
(BTW, I just started coding, so I'm sorry if it's not advanced)

Code: Select all
factor = 0
product = 0
SumOfProducts = 0

while True:
if product == 999:
ThreeProductTotal = SumOfProducts
break
else:
factor += 1
product = 3 * factor
SumOfProducts += product

factor = 0
product = 0
SumOfProducts = 0

while True:
if product == 995:
FiveProductTotal = SumOfProducts
break
else:
factor += 1
product = 5 * factor
SumOfProducts += product

print(ThreeProductTotal + FiveProductTotal)
Last edited by metulburr on Fri Jul 10, 2015 4:03 am, edited 1 time in total.
Reason: added code tags
E3x3

Posts: 2
Joined: Tue Jul 07, 2015 10:34 pm

### Re: (#1) What am I doing wrong?

You are double counting numbers.
Multiples of 3 or 5.

So currently you are counting numbers like 15 twice.
Also, there is a simpler way.
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: (#1) What am I doing wrong?

Please explain how I can fix it?
E3x3

Posts: 2
Joined: Tue Jul 07, 2015 10:34 pm

### Re: (#1) What am I doing wrong?

The two things that come to mind are to (1) not double count or (2) after double counting, remove those double counted numbers from your sum.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.

micseydel

Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

### Re: (#1) What am I doing wrong?

A picture sometimes says more than 1000 words could:
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe