Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70428
| References | <cc416b4b-e19d-49b9-abc2-86bcff455f9c@googlegroups.com> <CAPTjJmp6dHY-YOYbHoJ1_mYzKTQzvq12wnw7tM6jDsdR4TfGuw@mail.gmail.com> |
|---|---|
| Date | 2014-04-20 15:15 -0400 |
| Subject | Re: symple programming task |
| From | Joel Goldstick <joel.goldstick@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9386.1398021329.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Sun, Apr 20, 2014 at 3:02 PM, Chris Angelico <rosuav@gmail.com> wrote: > On Mon, Apr 21, 2014 at 4:43 AM, Ivan Ivanivich <ivriabtsov@gmail.com> > wrote: > > [quot] > > 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. > > [/quote] > > > > this task from http://projecteuler.net/ site > > > > I wrote a solution in python > > > > http://pastebin.com/QXtNuRWU > > > > this script returned correctly result if "basis < 10", but if "basis < > 1000" result is 266333 and it is not correctly answer on site > http://projecteuler.net > > Try listing the actual numbers you're summing, and check if there's a > problem there. Are all the numbers you expect appearing? Are any you > don't want there? > > (I can see exactly what your problem is, but I'd rather give hints > rather than simply tell you outright what's wrong.) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > I second Chris's comments. Also, better to paste your code in email. More people will look at it, especially since it is short. 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: for i in range(1000): Its a more pythonic idiom. Also use 4 spaces, not 8 for indents. Minor points. Print() is your friend -- Joel Goldstick http://joelgoldstick.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-20 11:43 -0700
Re: symple programming task Chris Angelico <rosuav@gmail.com> - 2014-04-21 05:02 +1000
Re: symple programming task Peter Otten <__peter__@web.de> - 2014-04-20 21:11 +0200
Re: symple programming task Joel Goldstick <joel.goldstick@gmail.com> - 2014-04-20 15:15 -0400
Re: symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-20 12:27 -0700
Re: symple programming task Joshua Landau <joshua@landau.ws> - 2014-04-21 12:43 +0100
Re: symple programming task Ivan Ivanivich <ivriabtsov@gmail.com> - 2014-04-21 06:21 -0700
Re: symple programming task Tim Chase <python.list@tim.thechases.com> - 2014-04-21 08:39 -0500
Re: symple programming task Chris Angelico <rosuav@gmail.com> - 2014-04-21 23:43 +1000
csiph-web