feat: Add a percentage function to the calculator #18

Merged
typosaurus merged 2 commits from typosaurus/16-add-a-percentage-function-to-the-calculator into main 2026-07-26 21:51:01 +02:00
Showing only changes of commit e11ca4b376 - Show all commits

View File

@ -1,6 +1,6 @@
# retoor <retoor@molodetz.nl>
from typing import Sequence
from typing import Sequence, Union
def add(left: int, right: int) -> int:
@ -32,3 +32,10 @@ def variance(values: Sequence[float]) -> float:
return sum((x - mean) ** 2 for x in values) / len(values)
def percentage(value: Union[int, float], total: Union[int, float]) -> float:
if total == 0:
raise ValueError
return (value / total) * 100