-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsolution.py
More file actions
34 lines (26 loc) · 789 Bytes
/
solution.py
File metadata and controls
34 lines (26 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
SUBMIT = True
def prime_check(n: int) -> bool:
if n <= 1:
return False
if n == 2:
return True
if n % 2 == 0:
return False
limite = int(n**0.5) + 1
for i in range(3, limite, 2):
if n % i == 0:
return False
return True
def test() -> None:
"""Simple self-test for Primality Test."""
cases = {2: True, 4: False, 17: True, 1: False, 0: False, 97: True}
for n, expected in cases.items():
try:
res = prime_check(n)
assert res == expected, f"Failed for n={n}: expected {expected}, got {res}"
except AssertionError as e:
print(f"❌ {e}")
return
print("✅ All tests passed!")
if __name__ == "__main__":
test()