Skip to content

Commit 968e6ca

Browse files
committed
Solution
1 parent b991c34 commit 968e6ca

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

app/main.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# write your code here
1+
class Animal:
2+
alive = []
3+
4+
def __init__(self, name: str,
5+
health: int = 100,
6+
hidden: bool = False) -> None:
7+
self.health = health
8+
self.name = name
9+
self.hidden = hidden
10+
if health > 0:
11+
Animal.alive.append(self)
12+
13+
def __repr__(self) -> str:
14+
return (
15+
f"{{Name: {self.name},"
16+
f" Health: {self.health},"
17+
f" Hidden: {self.hidden}}}"
18+
)
19+
20+
21+
class Herbivore(Animal):
22+
23+
def hide(self) -> None:
24+
self.hidden = not self.hidden
25+
26+
27+
class Carnivore(Animal):
28+
29+
@staticmethod
30+
def bite(victim: Herbivore) -> None:
31+
if victim.hidden is False and isinstance(victim, Herbivore) is True:
32+
victim.health -= 50
33+
if victim.health <= 0:
34+
Animal.alive.pop(Animal.alive.index(victim))

0 commit comments

Comments
 (0)