From 596bdbbe250d779760b485c24f0f42aae6fd72df Mon Sep 17 00:00:00 2001 From: Misha Zubritsky Date: Tue, 10 Oct 2023 19:41:56 +0300 Subject: [PATCH] Solution (3) --- app/main.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index c308a7f0..8f007360 100644 --- a/app/main.py +++ b/app/main.py @@ -13,7 +13,7 @@ def __init__( self.hidden = hidden Animal.alive.append(self) - def __str__(self) -> str: + def __repr__(self) -> str: return ("{" + f"Name: {self.name}, " f"Health: {self.health}, " f"Hidden: {self.hidden}" + "}") @@ -21,18 +21,13 @@ def __str__(self) -> str: 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): def bite(self, herb: Herbivore) -> None: - if type(herb) == Carnivore: - pass - elif not herb.hidden: + if isinstance(herb, Herbivore) and not herb.hidden: herb.health -= 50 if herb.health <= 0: