[Tutor] help with prime number program

Adam adam.jtm30 at gmail.com
Mon Oct 31 00:17:59 CET 2005


 > 1. What is 'exit'?

> instead of exit I can use break so that the loop will stop executing
>
> > 2. What is 'number - math.sqrt'?
> for math.sqrt I could use math.sqrt(n) so that it would take the sqrt of n
> which is entered in by the user
>
>
> However for the output I am still receiving
>
> enter a number greater than 2: 49
> 49 is prime
> 49 is prime
> 49 is prime
> 49 is prime
> 49 is prime
> 49 is not prime


The problem is using break just breaks from the loop and then goes into the
next instruction being
print number, "is prime"
As Danny suggested before using return will stop the entire function rather
than the just the loop.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051030/5c380157/attachment-0001.htm


More information about the Tutor mailing list