Skip to content

Commit

Permalink
Implemented necessary classes and methods, but I couldn't find a way …
Browse files Browse the repository at this point in the history
…to make line 17 shorter without changing the output
  • Loading branch information
raychw committed Oct 8, 2023
1 parent b991c34 commit bad7de4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# write your code here
class Animal:
alive = []

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

self.health = health
self.name = name
self.hidden = hidden
self.alive.append(self)

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


class Herbivore(Animal):
def hide(self) -> None:
self.hidden = not self.hidden


class Carnivore(Animal):
@classmethod
def bite(cls, herbivore: Animal) -> None:
if isinstance(herbivore, Herbivore) and not herbivore.hidden:
herbivore.health -= 50

if herbivore.health <= 0:
cls.alive.remove(herbivore)

0 comments on commit bad7de4

Please sign in to comment.