feat: Add an average function to the calculator #12
@ -25,6 +25,12 @@ def clamp_to_byte(value: int) -> int:
|
||||
return max(0, min(255, value))
|
||||
|
||||
|
||||
def average(values: list[int | float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
return sum(values) / len(values)
|
||||
|
||||
|
||||
def variance(values: Sequence[float]) -> float:
|
||||
if not values:
|
||||
raise ValueError
|
||||
@ -37,5 +43,3 @@ def percentage(value: Union[int, float], total: Union[int, float]) -> float:
|
||||
raise ValueError
|
||||
return (value / total) * 100
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user