Skip to content

Commit

Permalink
Solution with mentors advice
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii-Silenko committed Oct 11, 2023
1 parent ff5f594 commit 5125c52
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def __init__(self, name: str, health: int = 100) -> None:
Animal.alive.append(self)

def __repr__(self) -> str:
return "{" + f"Name: {self.name}, " \
f"Health: {self.health}, " \
f"Hidden: {self.hidden}" + "}"
return ("{" + f"Name: {self.name}, "
f"Health: {self.health}, "
f"Hidden: {self.hidden}" + "}")


class Herbivore(Animal):
Expand All @@ -19,8 +19,9 @@ def hide(self) -> None:


class Carnivore(Animal):
def bite(self, herbivore: Herbivore) -> None:
if isinstance(herbivore, Herbivore):
herbivore.health -= 50 if not herbivore.hidden else 0
@staticmethod
def bite(herbivore: Herbivore) -> None:
if isinstance(herbivore, Herbivore) and not herbivore.hidden:
herbivore.health -= 50
if herbivore.health <= 0:
super().alive.remove(herbivore)
super(Herbivore, herbivore).alive.remove(herbivore)

0 comments on commit 5125c52

Please sign in to comment.