From 08c57773f586cc8a9d35586011b583a25cdf02e8 Mon Sep 17 00:00:00 2001 From: Ostap Ivakh Date: Thu, 10 Aug 2023 21:56:26 +0300 Subject: [PATCH] 'Solution' --- app/main.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 8fbf3053..ea044f7a 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, appetite=3, is_hungry=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, appetite=7, is_hungry=is_hungry) + + def bring_slippers(self) -> None: + print("The slippers delivered!") + + +def feed_animals(animals_list: list) -> int: + total_food_points = 0 + + for animal in animals_list: + total_food_points += animal.feed() + + return total_food_points