October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function returns 1 if a number is prime; otherwise, it returns 0.
A prime number has only two divisors: 1 and itself. (The number 1 is not prime.)
The function is only required to work correctly on positive numbers and 0. The efficiency of the function, or lack thereof, is not the bug.
1. def isPrime( number ): 2. """ Check if a number is prime 3. 4. number: An integer. 5. 6. Returns: 1 if number is prime, 0 otherwise 7. """ 8. 9. """ Special-case 0 and 1, which are not prime. 10. """ 11. 12. if ( number == 0 ) or ( number == 1): 13. return 0 14. 15. """ Make a range of all numbers up to half of the 16. one ...
Read now
Unlock full access