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:
parent
9bc1788ae2
commit
e11ca4b376
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user