- #1
Ackbach
Gold Member
MHB
- 4,155
- 92
Here is this week's POTW:
-----
Write a computer program in Python to check a positive integer for primality. You may not use any built-in primitives that look like "IsPrime(n)". Check all the numbers up to $\sqrt{n}$, and skip the evens after 2.
Inputs: integer n. Check that the input is a positive integer. If it is not an integer, return an informative error message.
Outputs: boolean IsPrime, string Error. The boolean will be TRUE if the integer is prime, and FALSE if it is not. The error string will be empty if the input is a positive integer, and will return a suitable error message if it is not.
NB: because the function must return multiple values, define a class containing all the outputs, and return that.
The program must run correctly with Python Version 3.4.
-----
Remember to read the http://www.mathhelpboards.com/showthread.php?772-Problem-of-the-Week-%28POTW%29-Procedure-and-Guidelines to find out how to http://www.mathhelpboards.com/forms.php?do=form&fid=2!
-----
Write a computer program in Python to check a positive integer for primality. You may not use any built-in primitives that look like "IsPrime(n)". Check all the numbers up to $\sqrt{n}$, and skip the evens after 2.
Inputs: integer n. Check that the input is a positive integer. If it is not an integer, return an informative error message.
Outputs: boolean IsPrime, string Error. The boolean will be TRUE if the integer is prime, and FALSE if it is not. The error string will be empty if the input is a positive integer, and will return a suitable error message if it is not.
NB: because the function must return multiple values, define a class containing all the outputs, and return that.
The program must run correctly with Python Version 3.4.
-----
Remember to read the http://www.mathhelpboards.com/showthread.php?772-Problem-of-the-Week-%28POTW%29-Procedure-and-Guidelines to find out how to http://www.mathhelpboards.com/forms.php?do=form&fid=2!