Is a Number Prime?

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.

Source Code

						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 ...

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.