diff --git a/pipeline_test.py b/pipeline_test.py index 8e50afb..48127a5 100644 --- a/pipeline_test.py +++ b/pipeline_test.py @@ -1,23 +1,23 @@ """A small arithmetic calculator. Provides the :func:`calculate` function which performs basic arithmetic -operations (+, -, *, /, **, //) with proper error handling. +operations (+, -, *, /, **, //, %) with proper error handling. """ __all__ = ["calculate"] -def _check_div_zero(b: float | int, op: str) -> None: - if op in ("/", "//") and b == 0: +def _check_div_zero(b: float, op: str) -> None: + if op in ("/", "//", "%") and b == 0: raise ZeroDivisionError("division by zero") -def calculate(a: float | int, op: str, b: float | int) -> int | float: +def calculate(a: float, op: str, b: float) -> int | float: """Perform arithmetic operations with proper error handling. Args: a: First operand - op: Operation (+, -, *, /, **, //) + op: Operation (+, -, *, /, **, //, %) b: Second operand Returns: @@ -26,7 +26,7 @@ def calculate(a: float | int, op: str, b: float | int) -> int | float: Raises: TypeError: If op is not a string, or if a or b is not a number ValueError: If operation is unknown - ZeroDivisionError: If dividing by zero + ZeroDivisionError: If dividing or taking modulo by zero """ if not isinstance(op, str): raise TypeError(f"operation must be a string, got {type(op).__name__}") @@ -52,5 +52,7 @@ def calculate(a: float | int, op: str, b: float | int) -> int | float: return a ** b case "//": return a // b + case "%": + return a % b case _: raise ValueError(f"unknown operation: {op!r}")