Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'mrab': 0.05; 'sys': 0.07; '__name__': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; "'__main__':": 0.16; '1):': 0.16; 'range.': 0.16; 'wrote:': 0.18; 'thanks.': 0.20; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'sep': 0.31; 'url:python': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'christian': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'number,': 0.60; 'working,': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc :content-type; bh=mIWU+hBvo1zqHCFOTixX+8RLaldWrJPMFkvVYyNqQnk=; b=J75peoCbCTbOMAL2C2sKYWoubM+T+bYFJWSOKLT5ghLPto0weuVV4VETb1q0W/EAZ9 7gNzDqGNYc0qf1Lr+2L+fSbZvrVqU5G6dccqCoSBW2iB1ZVcctGjs3d1QhSVUll60rn1 7KgNwagqSwszQgGl0TGB4wqgUeoxAt/qd/ckMKGVF0Vj2YLCweyo5HSof/Nei6DTlswf Sfl+LdXS1EUlUdyYp5iLzDZHMSQLnpWJqWHRjIf4PLQURw2tzJMO6TfamYyPgA7wjy0t J8OvP8Yfflq/egfX0B3kmj0RhFwFNG17VEXscztfqEyF8Nzs4N/5y2xPQHYe1HbBKX4K Jetg== X-Received: by 10.152.19.5 with SMTP id a5mr13825346lae.21.1409945681528; Fri, 05 Sep 2014 12:34:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <540A0582.1010403@mrabarnett.plus.com> References: <1enj0att6bkrnvb81rhma5dbuk3h28agl8@4ax.com> <5409EE02.7030308@stoneleaf.us> <540A0582.1010403@mrabarnett.plus.com> From: Juan Christian Date: Fri, 5 Sep 2014 16:34:21 -0300 Subject: Re: My backwards logic Cc: Python Content-Type: multipart/alternative; boundary=089e0149422a800c020502568f59 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409946021 news.xs4all.nl 2933 [2001:888:2000:d::a6]:43424 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77612 --089e0149422a800c020502568f59 Content-Type: text/plain; charset=UTF-8 What's [snip] ?? On Fri, Sep 5, 2014 at 3:48 PM, MRAB wrote: > On 2014-09-05 18:35, Juan Christian wrote: > >> I made this code just for fun and learning, it's working, but would this >> be a good approach? Thanks. >> >> import sys >> >> >> def prime_checker(start = 1, stop = 1): >> > > In Python, the standard is to use a half-open range. > > for number in range(start, stop + 1): >> divisors = [(number % x) for x in range(1, number + 1)] >> print("{n} prime? {r}".format(n = number, r = >> (divisors.count(0) == 2))) >> >> You want to know only whether it's prime, so why continue looking after > finding a factor? > >> >> if __name__ == '__main__': >> prime_checker(int(sys.argv[1]), int(sys.argv[2])) >> >> [snip] > > -- > https://mail.python.org/mailman/listinfo/python-list > --089e0149422a800c020502568f59 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
What's [snip] ??


On Fri, Sep 5, 2014 at 3:48 PM, MRAB <= span dir=3D"ltr"><python@mrabarnett.plus.com> wrote:
On 2014-09-05 18:35, Juan Christian wr= ote:
I made this code just for fun and learning, it's working, but would thi= s
be a good approach? Thanks.

import sys


def prime_checker(start =3D 1, stop =3D 1):

In Python, the standard is to use a half-open range.

=C2=A0 =C2=A0 for number in range(start, stop + 1):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 divisors =3D [(number % x) for x in range(1, nu= mber + 1)]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print("{n} prime? {r}".= format(n =3D number, r =3D (divisors.count(0) =3D=3D 2)))

You want to know only whether it's prime, so why continue looking after=
finding a factor?

if __name__ =3D=3D '__main__':
=C2=A0 =C2=A0 prime_checker(int(sys.argv[1]), int(sys.argv[2]))

[snip]

--
https://mail.python.org/mailman/listinfo/python-list

--089e0149422a800c020502568f59--