MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / is_prime

Function is_prime

20-executors/primes/primes.py:32–44  ·  view source on GitHub ↗
(n: int)

Source from the content-addressed store, hash-verified

30
31# tag::IS_PRIME[]
32def is_prime(n: int) -> bool:
33 if n < 2:
34 return False
35 if n == 2:
36 return True
37 if n % 2 == 0:
38 return False
39
40 root = math.isqrt(n)
41 for i in range(3, root + 1, 2):
42 if n % i == 0:
43 return False
44 return True
45# end::IS_PRIME[]
46
47if __name__ == '__main__':

Callers 2

checkFunction · 0.90
primes.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected