feat: Add a percentage function to the calculator #18
@ -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