input: positive integer 'number' returns true if 'number' is prime otherwise false.
(number)
| 40 | """ |
| 41 | |
| 42 | def isPrime(number): |
| 43 | """ |
| 44 | input: positive integer 'number' |
| 45 | returns true if 'number' is prime otherwise false. |
| 46 | """ |
| 47 | import math # for function sqrt |
| 48 | |
| 49 | # precondition |
| 50 | assert isinstance(number,int) and (number >= 0) , \ |
| 51 | "'number' must been an int and positive" |
| 52 | |
| 53 | status = True |
| 54 | |
| 55 | # 0 and 1 are none primes. |
| 56 | if number <= 1: |
| 57 | status = False |
| 58 | |
| 59 | for divisor in range(2,int(round(math.sqrt(number)))+1): |
| 60 | |
| 61 | # if 'number' divisible by 'divisor' then sets 'status' |
| 62 | # of false and break up the loop. |
| 63 | if number % divisor == 0: |
| 64 | status = False |
| 65 | break |
| 66 | |
| 67 | # precondition |
| 68 | assert isinstance(status,bool), "'status' must been from type bool" |
| 69 | |
| 70 | return status |
| 71 | |
| 72 | # ------------------------------------------ |
| 73 |
no outgoing calls
no test coverage detected