From 9d986dfdde97ecb08f4a08b658354c88d5106644 Mon Sep 17 00:00:00 2001 From: valikdeb <73042683+valikdeb@users.noreply.github.com> Date: Fri, 15 Sep 2023 01:40:23 +0300 Subject: [PATCH] Solution --- app/main.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..c272c3c1 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,30 @@ -# write your code here +class Animal: + alive = [] + + def __init__(self, name: str, + health: int = 100, + hidden: bool = False) -> None: + self.name = name + self.health = health + self.hidden = hidden + Animal.alive.append(self) + + def __repr__(self) -> str: + name = self.name + health = self.health + hidden = self.hidden + return f"{{Name: {name}, Health: {health}, Hidden: {hidden}}}" + + +class Herbivore(Animal): + def hide(self) -> None: + self.hidden = not self.hidden + + +class Carnivore(Animal): + @staticmethod + def bite(other_animal: Animal) -> None: + if isinstance(other_animal, Herbivore) and not other_animal.hidden: + other_animal.health -= 50 + if other_animal.health <= 0: + Animal.alive.remove(other_animal)