<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Apr 20, 2014 at 3:02 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Mon, Apr 21, 2014 at 4:43 AM, Ivan Ivanivich <<a href="mailto:ivriabtsov@gmail.com">ivriabtsov@gmail.com</a>> wrote:<br>
> [quot]<br>
> 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.<br>
><br>
> Find the sum of all the multiples of 3 or 5 below 1000.<br>
> [/quote]<br>
><br>
> this task from <a href="http://projecteuler.net/" target="_blank">http://projecteuler.net/</a> site<br>
><br>
> I wrote a solution in python<br>
><br>
> <a href="http://pastebin.com/QXtNuRWU" target="_blank">http://pastebin.com/QXtNuRWU</a><br>
><br>
> this script returned correctly result if "basis < 10", but if "basis < 1000" result is 266333 and it is not correctly answer on site <a href="http://projecteuler.net" target="_blank">http://projecteuler.net</a><br>
<br>
</div>Try listing the actual numbers you're summing, and check if there's a<br>
problem there. Are all the numbers you expect appearing? Are any you<br>
don't want there?<br>
<br>
(I can see exactly what your problem is, but I'd rather give hints<br>
rather than simply tell you outright what's wrong.)<br>
<br>
ChrisA<br>
<span class="HOEnZb"><font color="#888888">--<br>
<a href="https://mail.python.org/mailman/listinfo/python-list" target="_blank">https://mail.python.org/mailman/listinfo/python-list</a><br>
</font></span></blockquote></div><br></div><div class="gmail_extra">I second Chris's comments. Also, better to paste your code in email. More people will look at it, especially since it is short.<br><br></div><div class="gmail_extra">
It looks like you are looping thru all the numbers twice -- once for each divisor. You don't need to do that. You can loop thru and test for each divisor on each loop. You might want to ditch the while loop and use a for loop over a range:<br>
<br></div><div class="gmail_extra">for i in range(1000):<br><br></div><div class="gmail_extra">Its a more pythonic idiom. Also use 4 spaces, not 8 for indents. Minor points.<br><br></div><div class="gmail_extra">Print() is your friend<br clear="all">
</div><div class="gmail_extra"><br>-- <br><div dir="ltr"><div>Joel Goldstick<br></div><a href="http://joelgoldstick.com" target="_blank">http://joelgoldstick.com</a><br></div>
</div></div>