From cb035790d593d821e2afd744c3240dec845de96c Mon Sep 17 00:00:00 2001 From: Daniil Hinzburh <2ilgan1601@gmail.com> Date: Wed, 23 Aug 2023 21:50:37 +0300 Subject: [PATCH 1/3] task completed --- app/main.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 8fbf3053..4e4ff60c 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,42 @@ -# 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 + else: + 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: Animal) -> int: + total_food_points = 0 + for animal in animals: + total_food_points += animal.feed() + return total_food_points From a00c86d2452f697b27f01bab86b647fb977b7f72 Mon Sep 17 00:00:00 2001 From: Daniil Hinzburh <2ilgan1601@gmail.com> Date: Wed, 23 Aug 2023 22:17:58 +0300 Subject: [PATCH 2/3] task completed 2 --- app/main.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/main.py b/app/main.py index 4e4ff60c..d7ea4385 100644 --- a/app/main.py +++ b/app/main.py @@ -15,8 +15,7 @@ def feed(self) -> int: print(f"Eating {self.appetite} food points...") self.is_hungry = False return self.appetite - else: - return 0 + return 0 class Cat(Animal): @@ -35,8 +34,5 @@ def bring_slippers(self) -> None: print("The slippers delivered!") -def feed_animals(animals: Animal) -> int: - total_food_points = 0 - for animal in animals: - total_food_points += animal.feed() - return total_food_points +def feed_animals(animals: list) -> int: + return sum(animal.feed() for animal in animals) From 976c7c2d7fbfcde2ae287acd60bed3b66fc56b0a Mon Sep 17 00:00:00 2001 From: Daniil Hinzburh <2ilgan1601@gmail.com> Date: Thu, 24 Aug 2023 10:48:24 +0300 Subject: [PATCH 3/3] task completed 3 --- app/main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index d7ea4385..7ad4a875 100644 --- a/app/main.py +++ b/app/main.py @@ -22,7 +22,8 @@ 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: + @staticmethod + def catch_mouse() -> None: print("The hunt began!") @@ -30,7 +31,8 @@ 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: + @staticmethod + def bring_slippers() -> None: print("The slippers delivered!")