From 7fab072a60572674deda69223b01f185fb03f344 Mon Sep 17 00:00:00 2001 From: Andrii Hrabovyi Date: Fri, 15 Sep 2023 14:25:59 +0300 Subject: [PATCH] Changes --- app/main.py | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/app/main.py b/app/main.py index 1741b1b7..458459b6 100644 --- a/app/main.py +++ b/app/main.py @@ -13,27 +13,23 @@ def __init__( Animal.alive.append(self) def __repr__(self) -> str: - return f"" \ - f"{{Name: {self.name}," \ - f" Health: {self.health}," \ - f" Hidden: {self.hidden}" \ - f"}}" + return ( + f"{{Name: {self.name}, " + f"Health: {self.health}, " + f"Hidden: {self.hidden}" + f"}}" + ) class Herbivore(Animal): def hide(self) -> None: - if not self.hidden: - self.hidden = True - else: - self.hidden = False + self.hidden = not self.hidden class Carnivore(Animal): @staticmethod - def bite(target: Animal) -> None: - if isinstance(target, Carnivore) or target.hidden: - pass - else: - target.health -= 50 - if target.health <= 0: - Animal.alive.remove(target) + def bite(herbivore: Animal) -> None: + if isinstance(herbivore, Herbivore) and not herbivore.hidden: + herbivore.health -= 50 + if herbivore.health <= 0: + Animal.alive.remove(herbivore)