Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added ex00/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions ex00/give_bmi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""BMI calculation utilities."""

from typing import Iterable, Union

Number = Union[int, float]


def _compute_bmi(weight: Number, height: Number) -> float:
"""Compute the BMI for a single height/weight pair."""
if height == 0:
raise ValueError("height cannot be zero")
return float(weight) / float(height) ** 2


def give_bmi(
height: Iterable[Number], weight: Iterable[Number]
) -> list[float]:
"""Return the list of BMI values for each pair of height and weight."""
heights = list(height)
weights = list(weight)
if len(heights) != len(weights):
raise ValueError("height and weight must have the same length")
return [_compute_bmi(w, h) for h, w in zip(heights, weights)]


def apply_limit(bmi: Iterable[float], limit: Number) -> list[float]:
"""Filter BMI values strictly greater than limit."""
return [value for value in bmi if value > float(limit)]


def main() -> None:
"""Demonstration of BMI computations."""
heights = [1.75, 1.8, 1.6]
weights = [70, 80, 50]
bmi = give_bmi(heights, weights)
print("BMI values:", bmi)
print("Above limit:", apply_limit(bmi, 22))


if __name__ == "__main__":
main()
Empty file added tester/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions tester/test_ex00.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Basic tests for ex00.give_bmi."""

from ex00.give_bmi import apply_limit, give_bmi


def main() -> None:
"""Run a simple test scenario."""
heights = [1.75, 1.8, 1.6]
weights = [70, 80, 50]
bmi = give_bmi(heights, weights)
print(bmi)
print(apply_limit(bmi, 22))


if __name__ == "__main__":
main()