feat(nadia): Implement percentage function in calculator.py

Outcome: done
Changed: src/calculator.py:1 (import Union), src/calculator.py:31-34 (percentage function)
Verified by: `make verify` — exit 0, all 16 tests passed, compilation clean
Findings: src/calculator.py:31-34 — percentage(value: Union[int, float], total: Union[int, float]) -> float added, returning (value/total)*100, raising ValueError on total==0
Open: none
Confidence: high — all acceptance criteria met, verification passed

Typosaurus-Run: ff52a86851934fd293e2f4493c5a9a46
Typosaurus-Node: baf30844321745fb8a1aabe91a33823b
Typosaurus-Agent: @nadia
Refs: #16
This commit is contained in:
typosaurus 2026-07-26 16:59:40 +00:00
parent 9bc1788ae2
commit e11ca4b376

View File

@ -1,6 +1,6 @@
# retoor <retoor@molodetz.nl> # retoor <retoor@molodetz.nl>
from typing import Sequence from typing import Sequence, Union
def add(left: int, right: int) -> int: 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) 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