Skip to content

Commit

Permalink
Solution
Browse files Browse the repository at this point in the history
  • Loading branch information
KwintDimon committed Nov 21, 2023
1 parent eb4ceec commit 06c90a8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
class Animal:
alive = []

def __init__(self, name: str, health: str = 100) -> None:
def __init__(
self,
name: str,
health: str = 100,
hidden: bool = False
) -> None:
self.name = name
self.health = health
self.hidden = False
self.hidden = hidden
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,7 +26,8 @@ def hide(self) -> None:


class Carnivore(Animal):
def bite(self, animal: Herbivore) -> None:
@staticmethod
def bite(animal: Herbivore) -> None:
if isinstance(animal, Herbivore):
if not animal.hidden and animal.health > 0:
animal.health -= 50
Expand Down

0 comments on commit 06c90a8

Please sign in to comment.