Skip to content

Commit

Permalink
solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombardier256 committed Dec 13, 2024
1 parent faa256e commit 40278e9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# write your code here
class Animal:
alive = list()

def __init__(
self, name: str, health: int = 100, hidden: bool = False) -> None:
self.name = name
self.health = health
self.hidden = hidden
self.alive.append(self)

def __repr__(self) -> dict:
animal = (f"{{Name: {self.name}, Health: {self.health},"
f" Hidden: {self.hidden}}}")
return animal


class Herbivore(Animal):
def hide(self) -> None:
if self.hidden:
self.hidden = False
else:
self.hidden = True


class Carnivore(Animal):
def bite(self, another_animal: Animal) -> None:
if not another_animal.hidden and isinstance(another_animal, Herbivore):
another_animal.health -= 50
if another_animal.health < 1:
Animal.alive.remove(another_animal)

0 comments on commit 40278e9

Please sign in to comment.