From b594a53b989763e367dbc3069c4c0f31cc0dadb9 Mon Sep 17 00:00:00 2001 From: ChaiMegz Date: Sat, 20 Sep 2025 20:53:00 -0500 Subject: [PATCH] Implemented arithmetic functions (add_numbers, factorial, is_prime) --- src/arithmetic/arithmetic.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/arithmetic/arithmetic.py b/src/arithmetic/arithmetic.py index 86f6960..4d83118 100644 --- a/src/arithmetic/arithmetic.py +++ b/src/arithmetic/arithmetic.py @@ -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: @@ -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: @@ -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