From 82c839b3b7ceaa098cd16ebbaa521905b4dbb0e1 Mon Sep 17 00:00:00 2001 From: Rafael Verissimo <32659361+raveriss@users.noreply.github.com> Date: Tue, 10 Jun 2025 10:52:05 +0200 Subject: [PATCH] Remove pycache files --- ex00/__init__.py | 0 ex00/give_bmi.py | 41 +++++++++++++++++++++++++++++++++++++++++ tester/__init__.py | 0 tester/test_ex00.py | 16 ++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 ex00/__init__.py create mode 100644 ex00/give_bmi.py create mode 100644 tester/__init__.py create mode 100644 tester/test_ex00.py diff --git a/ex00/__init__.py b/ex00/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ex00/give_bmi.py b/ex00/give_bmi.py new file mode 100644 index 0000000..6fb4c48 --- /dev/null +++ b/ex00/give_bmi.py @@ -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() diff --git a/tester/__init__.py b/tester/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tester/test_ex00.py b/tester/test_ex00.py new file mode 100644 index 0000000..8c2ce30 --- /dev/null +++ b/tester/test_ex00.py @@ -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()