From 7685db97ccab1d56b2485df9f2246d9ce3cd57ad Mon Sep 17 00:00:00 2001 From: Rostyslav Fostyk Date: Tue, 29 Oct 2024 18:18:52 +0200 Subject: [PATCH 1/2] init --- app/main.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 8fbf3053..9eb8ce0a 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,45 @@ -# write your code here +class Animal: + def __init__( + self, + name: str, + appetite: int, + is_hungry: bool = True + ) -> None: + self.name = name + self.appetite = appetite + self.is_hungry = is_hungry + + def print_name(self) -> None: + print(f"Hello, I'm {self.name}") + + def feed(self) -> int: + if self.is_hungry: + print(f"Eating {self.appetite} food points...") + self.is_hungry = False + return self.appetite + return 0 + + +class Cat(Animal): + def __init__(self, name: str, is_hungry: bool = True) -> None: + super().__init__(name, 3, is_hungry) + + def catch_mouse(self) -> None: + print("The hunt began!") + + +class Dog(Animal): + def __init__(self, name: str, is_hungry: bool = True) -> None: + super().__init__(name, 7, is_hungry) + + def bring_slippers(self) -> None: + print("The slippers delivered!") + + +def feed_animals(animals: list) -> int: + food_points = 0 + for animal in animals: + if animal.is_hungry: + animal.feed() + food_points += animal.appetite + return food_points From 1f68b5cdff7c82826b5e9cb9218545d91b283f05 Mon Sep 17 00:00:00 2001 From: Rostyslav Fostyk Date: Tue, 29 Oct 2024 18:29:13 +0200 Subject: [PATCH 2/2] resolve comments --- app/main.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index 9eb8ce0a..07bee219 100644 --- a/app/main.py +++ b/app/main.py @@ -37,9 +37,4 @@ def bring_slippers(self) -> None: def feed_animals(animals: list) -> int: - food_points = 0 - for animal in animals: - if animal.is_hungry: - animal.feed() - food_points += animal.appetite - return food_points + return sum(animal.feed() for animal in animals)