From 01f81d0b4658816a10255b459c7f0cdf180e4817 Mon Sep 17 00:00:00 2001 From: Your_Name Your_Surname Date: Tue, 3 Oct 2023 10:48:02 +0300 Subject: [PATCH] Solution --- app/main.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..b7ed0937 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,38 @@ -# write your code here +class Animal: + alive: list["Animal"] = [] + + def __init__( + self, name: str, + health: int = 100, + hidden: bool = False + ) -> None: + self.name = name + self.health = health + self.hidden = hidden + self.alive.append(self) + + def __repr__(self) -> str: + return (f"{'{'}Name: {self.name}," + f" Health: {self.health}, " + f"Hidden: {self.hidden}{'}'}") + + @classmethod + def del_dead_animal(cls, others: "Animal") -> None: + if others in cls.alive: + cls.alive.remove(others) + + +class Herbivore(Animal): + def hide(self) -> None: + if self.hidden: + self.hidden = False + else: + self.hidden = True + + +class Carnivore(Animal): + @staticmethod + def bite(other: "Animal") -> None: + if isinstance(other, Herbivore) and not other.hidden: + other.health = other.health - 50 + Animal.del_dead_animal(other)