From d009afc3477c949b16a3899faf5b686a1fae269a Mon Sep 17 00:00:00 2001 From: Prasanth Nalluri Date: Wed, 17 Sep 2025 21:24:21 +0000 Subject: [PATCH 1/3] added sample file --- sample.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 sample.txt diff --git a/sample.txt b/sample.txt new file mode 100644 index 0000000..e720fc7 --- /dev/null +++ b/sample.txt @@ -0,0 +1,2 @@ +hi + From b455175e4f41e241df95adc5153948ea5de257e3 Mon Sep 17 00:00:00 2001 From: Prasanth Nalluri Date: Wed, 17 Sep 2025 21:32:52 +0000 Subject: [PATCH 2/3] Implement arithmetic functions --- sample.txt | 2 -- src/arithmetic/arithmetic.py | 40 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) delete mode 100644 sample.txt diff --git a/sample.txt b/sample.txt deleted file mode 100644 index e720fc7..0000000 --- a/sample.txt +++ /dev/null @@ -1,2 +0,0 @@ -hi - diff --git a/src/arithmetic/arithmetic.py b/src/arithmetic/arithmetic.py index 86f6960..76fef9c 100644 --- a/src/arithmetic/arithmetic.py +++ b/src/arithmetic/arithmetic.py @@ -1,4 +1,4 @@ -"""arithmetic functions.""" +"""Arithmetic functions.""" from __future__ import annotations @@ -12,8 +12,13 @@ def add_numbers(a: int, b: int) -> int: Returns: Sum of a and b. + + Raises: + TypeError: if a or b is not an int """ - raise NotImplementedError + if not isinstance(a, int) or not isinstance(b, int): + raise TypeError("add_numbers requires integer arguments") + return a + b def factorial(n: int) -> int: @@ -27,8 +32,17 @@ def factorial(n: int) -> int: Raises: ValueError: if n is negative + TypeError: if n is not an int """ - raise NotImplementedError + if not isinstance(n, int): + raise TypeError("factorial requires an integer argument") + if n < 0: + raise ValueError("n must be non-negative") + + result = 1 + for i in range(2, n + 1): + result *= i + return result def is_prime(n: int) -> bool: @@ -42,5 +56,23 @@ def is_prime(n: int) -> bool: Returns: True if n is prime; otherwise False. + + Raises: + TypeError: if n is not an int """ - raise NotImplementedError + if not isinstance(n, int): + raise TypeError("is_prime requires an integer argument") + + 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 From cc72e7c5be7eec15b2824d414bbc141a5b5a37c0 Mon Sep 17 00:00:00 2001 From: Prasanth Nalluri Date: Wed, 17 Sep 2025 21:41:06 +0000 Subject: [PATCH 3/3] Implement arithmetic functions . --- src/arithmetic/arithmetic.py | 38 ++++++++---------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/arithmetic/arithmetic.py b/src/arithmetic/arithmetic.py index 76fef9c..4e825c2 100644 --- a/src/arithmetic/arithmetic.py +++ b/src/arithmetic/arithmetic.py @@ -1,4 +1,4 @@ -"""Arithmetic functions.""" +"""arithmetic functions.""" from __future__ import annotations @@ -12,12 +12,7 @@ def add_numbers(a: int, b: int) -> int: Returns: Sum of a and b. - - Raises: - TypeError: if a or b is not an int """ - if not isinstance(a, int) or not isinstance(b, int): - raise TypeError("add_numbers requires integer arguments") return a + b @@ -32,17 +27,13 @@ def factorial(n: int) -> int: Raises: ValueError: if n is negative - TypeError: if n is not an int """ - if not isinstance(n, int): - raise TypeError("factorial requires an integer argument") if n < 0: - raise ValueError("n must be non-negative") - - result = 1 - for i in range(2, n + 1): - result *= i - return result + raise ValueError("n must be a non-negative integer") + if n == 0 or n == 1: + return 1 + else: + return n * factorial(n - 1) def is_prime(n: int) -> bool: @@ -56,23 +47,10 @@ def is_prime(n: int) -> bool: Returns: True if n is prime; otherwise False. - - Raises: - TypeError: if n is not an int """ - if not isinstance(n, int): - raise TypeError("is_prime requires an integer argument") - 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: + for i in range(2, int(n**0.5) + 1): + if n % i == 0: return False - i += 6 return True