Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77626
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.012 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'value,': 0.04; '"if': 0.09; 'bits': 0.09; 'latter': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '"""return': 0.16; 'boolean': 0.16; 'btw': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hint': 0.16; 'zero.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'things.': 0.19; '(the': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'tells': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'nearly': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; "we'd": 0.29; 'am,': 0.29; "doesn't": 0.30; 'especially': 0.30; 'message- id:@mail.gmail.com': 0.30; 'work.': 0.31; 'getting': 0.31; 'away.': 0.31; 'factor': 0.31; 'sep': 0.31; "they'll": 0.31; 'yourself.': 0.31; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'found.': 0.36; 'returning': 0.36; 'useful': 0.36; 'rather': 0.38; 'that,': 0.38; 'aside': 0.39; 'how': 0.40; 'tell': 0.60; 'break': 0.61; 'times': 0.62; 'information': 0.63; 'telling': 0.64; 'more': 0.64; 'teach': 0.65; 'effectively': 0.66; 'truth': 0.81; 'cost,': 0.84; 'to:none': 0.92; 'factors': 0.97 |
| 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:cc :content-type; bh=8kxqN8AbITVooyL9fz32O8V9aUgmmqu+3DEArQgh8vs=; b=sgqXVc4s9qtM4L38GogN3DCymfl1P+WPZx3uqdZkm3LT97+uZ/RYa8n6fzFmtPdwMt tdX4vneKIl8nfx2cZyxZVvdFvpUY+rp7PCFVPVDDrieDeMQdATAqZsmen1Fs2eG64x/W jl4IPaB0BvO8fgsiitZEPX3AnPeB5jWB9mrftWkLuAyH3+xMfh82oJrD90VwCXpRePWA QOjgS/NTjysptIgLFs3qi8liZcQQhjZI+Jy/OdSXOFLj3cy7d+29diHV7PRIcf4BIg3m XqC8oICbbOk6dK6F5svNH8rEBT/muT5cGwMa8YaqWXr21TbVsNxFodDlZwAGfKHf7bga 62Sg== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.176.169 with SMTP id cj9mr8954434igc.14.1409960688291; Fri, 05 Sep 2014 16:44:48 -0700 (PDT) |
| In-Reply-To | <a1tj0a9sb7bo0qd2lpf7gl9gu3l0o1sniu@4ax.com> |
| References | <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <mailman.13795.1409936907.18130.python-list@python.org> <a1tj0a9sb7bo0qd2lpf7gl9gu3l0o1sniu@4ax.com> |
| Date | Sat, 6 Sep 2014 09:44:48 +1000 |
| Subject | Re: My backwards logic |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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.13814.1409960691.18130.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1409960691 news.xs4all.nl 2922 [2001:888:2000:d::a6]:58192 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77626 |
Show key headers only | View raw
On Sat, Sep 6, 2014 at 3:44 AM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
> BTW since I am getting no grade, I much prefer the answer than a hint.
> The best hint IMO is to tell me how you would do it.
But for your own learning, it's still better for you to do things
yourself. Giving you the answer doesn't teach you nearly as
effectively as giving you a hint and having you work out the answer
yourself.
But telling you how we'd do it can be useful too, especially when we
get down to the detaily bits where there are lots of ways to do
things. For instance, there's been a suggestion made a few times to
break the primality test out into a function... but compare these two:
def isprime(n):
"""Return True iff n is prime"""
def find_factor(n):
"""Return a factor of n, or None if n is prime"""
Aside from inverting the truth value, these are both tests of
primality - you can write "if isprime(n):" or "if find_factor(n):" and
they'll both work. (The latter is actually "iscomposite".) But the
second function is giving you a bit more information - it tells you
what factor it found.
As a general rule, try to avoid throwing information away. To prove
that n is composite, your function found a factor. Returning that,
rather than a boolean value, might make your function more useful; and
it's zero cost, because you know that factors of a number will never
be zero.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
My backwards logic Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-05 12:48 -0400
Re: My backwards logic MRAB <python@mrabarnett.plus.com> - 2014-09-05 17:57 +0100
Re: My backwards logic Bob Gailer <bgailer@gmail.com> - 2014-09-05 13:04 -0400
Re: My backwards logic John Gordon <gordon@panix.com> - 2014-09-05 17:08 +0000
Re: My backwards logic Ethan Furman <ethan@stoneleaf.us> - 2014-09-05 10:08 -0700
Re: My backwards logic Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-05 13:44 -0400
Re: My backwards logic Chris Kaynor <ckaynor@zindagigames.com> - 2014-09-05 11:17 -0700
Re: My backwards logic Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-05 15:04 -0600
Re: My backwards logic Chris Angelico <rosuav@gmail.com> - 2014-09-06 09:44 +1000
Re: My backwards logic Chris Kaynor <ckaynor@zindagigames.com> - 2014-09-05 10:09 -0700
Re:My backwards logic Dave Angel <davea@davea.name> - 2014-09-05 13:15 -0400
Re: My backwards logic Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-05 11:17 -0600
Re: My backwards logic Juan Christian <juan0christian@gmail.com> - 2014-09-05 14:35 -0300
Re: My backwards logic Ethan Furman <ethan@stoneleaf.us> - 2014-09-05 11:41 -0700
Re: My backwards logic MRAB <python@mrabarnett.plus.com> - 2014-09-05 19:48 +0100
Re: My backwards logic Juan Christian <juan0christian@gmail.com> - 2014-09-05 16:34 -0300
Re: My backwards logic Paul Rubin <no.email@nospam.invalid> - 2014-09-05 13:07 -0700
Re: My backwards logic Rustom Mody <rustompmody@gmail.com> - 2014-09-05 18:24 -0700
Re: My backwards logic Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-05 20:54 +0100
Re: My backwards logic Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-05 17:49 -0400
Re: My backwards logic Chris Kaynor <ckaynor@zindagigames.com> - 2014-09-05 15:14 -0700
Re: My backwards logic Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-05 18:36 -0400
Re: My backwards logic Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-05 16:35 -0600
Re: My backwards logic Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-05 19:05 -0400
Re: My backwards logic Dave Angel <davea@davea.name> - 2014-09-05 23:10 -0400
Re: My backwards logic Juan Christian <juan0christian@gmail.com> - 2014-09-05 22:54 -0300
Re: My backwards logic Rustom Mody <rustompmody@gmail.com> - 2014-09-05 18:58 -0700
Posting style: interleaved responses (was: My backwards logic) Ben Finney <ben+python@benfinney.id.au> - 2014-09-06 12:37 +1000
Re: Posting style: interleaved responses (was: My backwards logic) Juan Christian <juan0christian@gmail.com> - 2014-09-06 00:06 -0300
Re: Posting style: interleaved responses (was: My backwards logic) Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-09-05 23:04 -0500
Re: My backwards logic Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-06 08:45 +0100
Re: My backwards logic Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-06 07:49 +0000
Prime testing [was Re: My backwards logic] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-06 20:38 +1000
Re: Prime testing [was Re: My backwards logic] Chris Angelico <rosuav@gmail.com> - 2014-09-06 20:42 +1000
Re: Prime testing [was Re: My backwards logic] Manolo Martínez <manolo@austrohungaro.com> - 2014-09-06 12:53 +0200
Re: Prime testing [was Re: My backwards logic] Peter Pearson <pkpearson@nowhere.invalid> - 2014-09-07 18:53 +0000
Re: Prime testing [was Re: My backwards logic] Manolo Martínez <manolo@austrohungaro.com> - 2014-09-07 21:09 +0200
Re: Prime testing [was Re: My backwards logic] Dan Stromberg <drsalists@gmail.com> - 2014-09-07 20:23 -0700
Re: Posting style: interleaved responses Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-06 08:46 +0100
csiph-web