Re: Finding prime numbers

2007-09-20 Thread Shawn Milochik
On 9/20/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On Sep 19, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > > > If you'd just search the archives, you would have found this: > > > > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > > > Yeah, but that's n

Re: Finding prime numbers

2007-09-20 Thread kyosohma
On Sep 19, 1:31 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > > If you'd just search the archives, you would have found this: > > >http://groups.google.com/group/comp.lang.python/browse_thread/thread/... > > Yeah, but that's no fun. ;o) Yes! Never do what you can fool others into doing for you

Re: [Tutor] Finding prime numbers

2007-09-20 Thread Nick Craig-Wood
Shawn Milochik <[EMAIL PROTECTED]> wrote: > Any improvements anyone? >>> import gmpy >>> for x in range(3,1000,2): ... if gmpy.is_prime(x): ... print x,"is prime" ... 3 is prime 5 is prime 7 is prime [...] >>> gmpy.is_prime(2**607-1) 1 >>> gmpy.is_prime(2**

Re: Finding prime numbers

2007-09-19 Thread Shawn Milochik
> If you'd just search the archives, you would have found this: > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/b134b2235e9c19a6/34857fb0b0b2a4b5?lnk=gst&q=prime+number&rnum=1#34857fb0b0b2a4b5 Yeah, but that's no fun. ;o) -- http://mail.python.org/mailman/listinfo/python

Re: Finding prime numbers

2007-09-19 Thread kyosohma
On Sep 19, 12:15 pm, "Shawn Milochik" <[EMAIL PROTECTED]> wrote: > Okay, I caught one bug already myself: > > for y in range(3,(math.sqrt(x) + 1)): > > should be > > for y in range(3,(int(math.sqrt(x)) + 1)): If you'd just search the archives, you would have found this: http://groups.google.com/

Re: [Tutor] Finding prime numbers

2007-09-19 Thread Shawn Milochik
Okay, I caught one bug already myself: for y in range(3,(math.sqrt(x) + 1)): should be for y in range(3,(int(math.sqrt(x)) + 1)): -- http://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] Finding prime numbers

2007-09-19 Thread Shawn Milochik
Here's my attempt: #!/usr/bin/env python import math for x in range(3,1000,2): isPrime = True for y in range(3,(math.sqrt(x) + 1)): if x % y == 0: isPrime = False break if isPrime: print "%d is prime." % x Notes: This doesn't bother with ev