diff --git a/src/calculator.py b/src/calculator.py index e4e6afd..059ceb1 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -1,5 +1,8 @@ # retoor +from typing import Union + + def add(left: int, right: int) -> int: return left + right @@ -20,3 +23,11 @@ def clamp(value: int, low: int, high: int) -> int: def clamp_to_byte(value: int) -> int: return max(0, min(255, value)) + + +def percentage(value: Union[int, float], total: Union[int, float]) -> float: + if total == 0: + raise ValueError + return (value / total) * 100 + +