use while loop to check a number is prime or not

asked 2017-08-18 05:29:56 -0500

anonymous user

Anonymous

use while loop to check a number is prime or not

edit retag flag offensive close merge delete

Comments

Looks like a homework problem ... can you be a little more specific?

kcrisman gravatar imagekcrisman ( 2017-08-18 12:29:51 -0500 )edit

If this is the question, then i remember the good old days in the school, as my answer was in the shape:

sage: def nothing( p ):
....:     print "Is %s a prime? %s" % ( p, p.is_prime() )
....:     
sage: while nothing( 2017 ):
....:     pass
....: 
Is 2017 a prime? True
sage: while nothing( 2018 ):
....:     pass
....: 
Is 2018 a prime? False

(Such homework questions deserve such solution answers.)

(Try it on your own risk, it works while the examiners come with a good sense of humor.)

(Note: nothing implicitly returns None, which is evaluated to the boolean value False tacitly by while.)

dan_fulea gravatar imagedan_fulea ( 2017-08-18 16:15:59 -0500 )edit