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


Groups > comp.lang.python > #70461

Re: symple programming task

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'variables': 0.07; '1000.': 0.09; 'solution,': 0.09; 'statements': 0.09; 'cc:addr:python- list': 0.11; '"if"': 0.16; '(3,': 0.16; '-tkc': 0.16; '1000):': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'ivan': 0.16; 'multiples': 0.16; 'pythonic': 0.16; 'range(0,': 0.16; 'subject:programming': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'mod': 0.31; 'problem': 0.35; 'version': 0.36; 'charset:us-ascii': 0.36; 'rather': 0.38; 'easy': 0.60; 'new': 0.61; 'sum': 0.64; 'more': 0.64; 'total': 0.65; 'to:addr:gmail.com': 0.65; 'evaluate': 0.72; 'received:50.22': 0.84
Date Mon, 21 Apr 2014 08:39:10 -0500
From Tim Chase <python.list@tim.thechases.com>
To Ivan Ivanivich <ivriabtsov@gmail.com>
Subject Re: symple programming task
In-Reply-To <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com>
References <cc416b4b-e19d-49b9-abc2-86bcff455f9c@googlegroups.com> <7f496a70-6b85-4bc9-bf33-7aeaad813d11@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
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 <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.9406.1398087564.18130.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1398087564 news.xs4all.nl 2880 [2001:888:2000:d::a6]:33897
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70461

Show key headers only | View raw


On 2014-04-21 06:21, Ivan Ivanivich wrote:
> > Find the sum of all the multiples of 3 or 5 below 1000.
> my new version of script:
> 
> total = 0
> div1 = 3
> div2 = 5
> for basis in range(0, 1000):
>         mod = basis % div1
>         if mod == 0:
>                 total = total + basis
>                 continue
>         mod = basis % div2
>         if mod == 0:
>                 total = total + basis
>                 continue
> 
> 
> 
> print("total = ", total)

Now that you have a working solution, I don't mind giving my more
pythonic solution:

  sum(dividend for dividend in range(1000)
    if any(dividend % divisor == 0 for divisor in (3, 5)))

which succinctly states the problem and makes it easy to
add/remove/change the divisors in one place rather than having to
define multiple variables to hold them and "if" statements to
evaluate them.

-tkc


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