[Tutor] Finding prime numbers

christopher.henk at allisontransmission.com christopher.henk at allisontransmission.com
Wed Sep 19 19:01:02 CEST 2007


tutor-bounces at python.org wrote on 09/19/2007 12:38:49 PM:

> Sorry about that.
> 
> I have posted the code below:
> 
> #!/usr/bin/env python
> 
> '''A program to generate prime numbers when given 2 numbers'''
> 
> def isPrime(number):
>     number=abs(int(number))
>     #1 is not considered a prime number
>     if number<2:
>         return False
>     #2 is the only even prime number
>     if number==2:
>         return True
>     #no even prime numbers after 2
>     if not number&1:
>         return False
>     #to find all prime numbers we need to go up to the
>     #square root of the highest odd number
>     for x in range(3,int(number**0.5)+1,2):
>         if number%x==0:
>             return False
>         return True

Looks like you want to move the return True out one level of indentation.

> > -- 
> > Michael Langford
> > Phone: 404-386-0495
> > Consulting: http://www.TierOneDesign.com/
> > Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Chris Henk
Allison Transmission
phone:  317.242.2569
fax:  317.242.3469
e-mail:  christopher.henk at allisontransmission.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070919/91590ebc/attachment.htm 


More information about the Tutor mailing list