Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70428

Re: symple programming task

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 <joel.goldstick@gmail.com>
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; '&lt;': 0.19; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'script': 0.25; '&gt;': 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 <CAPTjJmp6dHY-YOYbHoJ1_mYzKTQzvq12wnw7tM6jDsdR4TfGuw@mail.gmail.com>
References <cc416b4b-e19d-49b9-abc2-86bcff455f9c@googlegroups.com> <CAPTjJmp6dHY-YOYbHoJ1_mYzKTQzvq12wnw7tM6jDsdR4TfGuw@mail.gmail.com>
Date Sun, 20 Apr 2014 15:15:27 -0400
Subject Re: symple programming task
From Joel Goldstick <joel.goldstick@gmail.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type multipart/alternative; boundary=001a1135ef169a320704f77e34c4
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9386.1398021329.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


[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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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