From d8706012ab66aa91c1bfb6b5ccb61fa8ed54960d Mon Sep 17 00:00:00 2001 From: ve4nick Date: Sat, 7 Oct 2023 22:50:41 +0300 Subject: [PATCH] Solution --- app/main.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..b78b1553 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,27 @@ -# 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}}}") + + +class Herbivore(Animal): + def hide(self) -> None: + self.hidden = not self.hidden + + +class Carnivore(Animal): + def bite(self, herbivore: Herbivore) -> None: + if not herbivore.hidden and not isinstance(herbivore, Carnivore): + herbivore.health -= 50 + + if herbivore.health <= 0: + Animal.alive.remove(herbivore)