Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '21,': 0.07; '1000.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'wrote': 0.14; 'ivan': 0.16; 'loop.': 0.16; 'looping': 0.16; 'multiples': 0.16; 'pythonic': 0.16; 'subject:programming': 0.16; 'there?': 0.16; 'wrote:': 0.18; '<': 0.19; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'script': 0.25; '>': 0.26; 'task': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'returned': 0.30; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'that.': 0.31; 'minor': 0.31; 'there.': 0.32; 'url:python': 0.33; 'actual': 0.34; "i'd": 0.34; 'problem': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'list': 0.37; 'pm,': 0.38; 'rather': 0.38; 'expect': 0.39; 'url:mail': 0.40; 'tell': 0.60; 'numbers': 0.61; 'simply': 0.61; "you're": 0.61; 'sum': 0.64; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'natural': 0.68; '20,': 0.68; 'hints': 0.68; 'friend': 0.79; 'joel': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=dlO6S3PMRtC6fHDaamstIwGuyclR+LlMB7vr3wliPW8=; b=UFCa6jbxFd1B2LxAezFkpp+1dcSJt2uYvhmfUT/jvjiYgQ298sizvQCw7j7VJN+t9B 7l9fIbtOu/RS4YLIeuUADgyr5cnJYL0tqAQ60MsYDC/cFdmgv722ghvs7C+0GvHTPMOT nHzeQM8GID9wdEmIGSGgHd+g1K8p1aIrRFHf78RxgfLOj8O6FM1i1pXsVor9+PkCq6lQ gsM393/CaIO71gj75F/c0clAshiFhc8ExZlA75RXoK7qDNPRhSIElKxuXfmbngJhdhzV vo/rn7/J/DH1ctP3qzGaQfWQmTn3mf/rnY8QAYKEeLOEyYcQSAK7HY9EaNeHQq5Zt2ol hP2Q== MIME-Version: 1.0 X-Received: by 10.52.253.75 with SMTP id zy11mr22956275vdc.10.1398021327301; Sun, 20 Apr 2014 12:15:27 -0700 (PDT) In-Reply-To: References: Date: Sun, 20 Apr 2014 15:15:27 -0400 Subject: Re: symple programming task From: Joel Goldstick To: Chris Angelico Content-Type: multipart/alternative; boundary=001a1135ef169a320704f77e34c4 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 119 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1398021329 news.xs4all.nl 2915 [2001:888:2000:d::a6]:44954 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:70428 --001a1135ef169a320704f77e34c4 Content-Type: text/plain; charset=UTF-8 On Sun, Apr 20, 2014 at 3:02 PM, Chris Angelico wrote: > On Mon, Apr 21, 2014 at 4:43 AM, Ivan Ivanivich > 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 --001a1135ef169a320704f77e34c4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Sun, Apr 20, 2014 at 3:02 PM, Chris Angelico &= lt;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://past= ebin.com/QXtNuRWU
>
> this script returned correctly result if "basis < 10", bu= t if "basis < 1000" result is 266333 and it is not correctly a= nswer 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 sec= ond Chris's comments.=C2=A0 Also, better to paste your code in email.= =C2=A0 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 d= ivisor.=C2=A0 You don't need to do that.=C2=A0 You can loop thru and te= st for each divisor on each loop.=C2=A0 You might want to ditch the while l= oop and use a for loop over a range:

for i in range(1000):

Its a more pythonic idiom.=C2=A0 Also use 4 spaces,= not 8 for indents.=C2=A0 Minor points.

Print() is your friend

--
--001a1135ef169a320704f77e34c4--