Mathematics
Algorithms
Logic
Numbers
def prime_checker(n): a = 0 for i in range(2,n): if n == 2: return True break elif n%i == 0: return False a += 1 break if a == 0: return True
- def prime_checker(n):
if n < 4 or n==5:return n > 1if n % 2 == 0 or n % 3 == 0 or n % 5 == 0:return Falsei = 7sqrt_n = int(n ** 0.5)while i <= sqrt_n:if n % i == 0 or n % (i + 2) == 0:- a = 0
- for i in range(2,n):
- if n == 2:
- return True
- break
- elif n%i == 0:
- return False
i += 7return True- a += 1
- break
- if a == 0:
- return True
import codewars_test as test from solution import prime_checker @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(prime_checker(653), True) test.assert_equals(prime_checker(654), False) test.assert_equals(prime_checker(5), True) test.assert_equals(prime_checker(777), False)# test.assert_equals(prime_checker(977), True) test.assert_equals(prime_checker(125), False)# test.assert_equals(prime_checker(997), True) test.assert_equals(prime_checker(709), True) test.assert_equals(prime_checker(15), False)# test.assert_equals(prime_checker(11), True) test.assert_equals(prime_checker(13), True) test.assert_equals(prime_checker(17), True) test.assert_equals(prime_checker(19), True) test.assert_equals(prime_checker(23), True) test.assert_equals(prime_checker(29), True) test.assert_equals(prime_checker(1021), True)
- import codewars_test as test
- from solution import prime_checker
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
- test.assert_equals(prime_checker(653), True)
- test.assert_equals(prime_checker(654), False)
- test.assert_equals(prime_checker(5), True)
test.assert_equals(prime_checker(777), False)- test.assert_equals(prime_checker(777), False)#
- test.assert_equals(prime_checker(977), True)
test.assert_equals(prime_checker(125), False)- test.assert_equals(prime_checker(125), False)#
- test.assert_equals(prime_checker(997), True)
- test.assert_equals(prime_checker(709), True)
test.assert_equals(prime_checker(15), False)- test.assert_equals(prime_checker(15), False)#
- test.assert_equals(prime_checker(11), True)
- test.assert_equals(prime_checker(13), True)
- test.assert_equals(prime_checker(17), True)
- test.assert_equals(prime_checker(19), True)
- test.assert_equals(prime_checker(23), True)
- test.assert_equals(prime_checker(29), True)
- test.assert_equals(prime_checker(1021), True)