From c2c29577959f57e7d596b4628145860e24714c87 Mon Sep 17 00:00:00 2001 From: wonsky Date: Mon, 9 Oct 2023 12:39:33 +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..59998c3c 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): + @staticmethod + def bite(other: Herbivore) -> None: + if not other.hidden and isinstance(other, Herbivore): + other.health -= 50 + if other.health <= 0: + Animal.alive.remove(other)