From c8cce768d51e8ce54f6556c4ae234c5f4f311e00 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 7 Oct 2023 18:22:05 +0300 Subject: [PATCH] Solution --- app/main.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/main.py b/app/main.py index fa56336e..da9651d9 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) -> None: + self.name = name + self.health = health + self.hidden = False + Animal.alive.append(self) + + def __repr__(self) -> str: + return (f"{{Name: {self.name}," + f" Health: {self.health}," + f" Hidden: {self.hidden}}}") + + def die(self) -> list: + Animal.alive.remove(self) + + +class Herbivore(Animal): + def hide(self) -> None: + self.hidden = not self.hidden + + +class Carnivore(Animal): + def bite(self, herbivore: str) -> list: + if isinstance(herbivore, Herbivore) and not herbivore.hidden: + herbivore.health -= 50 + if herbivore.health <= 0: + herbivore.die()