MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / isPrime

Function isPrime

src/gamesbyexample/primenumbers.py:35–48  ·  view source on GitHub ↗

Returns True if number is prime, otherwise returns False.

(number)

Source from the content-addressed store, hash-verified

33
34
35def isPrime(number):
36 """Returns True if number is prime, otherwise returns False."""
37 # Handle special cases:
38 if number < 2:
39 return False
40 elif number == 2:
41 return True
42
43 # Try to evenly divide number by all numbers from 2 up to number's
44 # square root.
45 for i in range(2, int(math.sqrt(number)) + 1):
46 if number % i == 0:
47 return False
48 return True
49
50
51# If this program was run (instead of imported), run the game:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected