Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Hrabovyi committed Sep 15, 2023
1 parent a393e00 commit 7fab072
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7fab072

Please sign in to comment.