from math import sqrt def prime(x): end = min(int(sqrt(x) + 1), x) return all(x % i != 0 for i in range(2, end))
- from math import sqrt
- def prime(x):
counter = 0for i in range(1,x):if x % i is 0:counter += 1if counter is 0:return Trueelse:return False- end = min(int(sqrt(x) + 1), x)
- return all(x % i != 0 for i in range(2, end))
test.assert_equals(prime(12345),False) test.assert_equals(prime(2),True) test.assert_equals(prime(3),True) test.assert_equals(prime(4),False) test.assert_equals(prime(12),False)
- test.assert_equals(prime(12345),False)
- test.assert_equals(prime(2),True)
- test.assert_equals(prime(3),True)
- test.assert_equals(prime(4),False)
- test.assert_equals(prime(12),False)