Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/arithmetic/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def add_numbers(a: int, b: int) -> int:
Returns:
Sum of a and b.
"""
raise NotImplementedError
total = a + b
return total


def factorial(n: int) -> int:
Expand All @@ -28,7 +29,14 @@ def factorial(n: int) -> int:
Raises:
ValueError: if n is negative
"""
raise NotImplementedError
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
result = 1

for i in range(2, n + 1):
result *= i

return result


def is_prime(n: int) -> bool:
Expand All @@ -43,4 +51,16 @@ def is_prime(n: int) -> bool:
Returns:
True if n is prime; otherwise False.
"""
raise NotImplementedError
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6

return True
Loading