From 30d4e7a7c9e575077fc43a799bcf4fb8180e06ba Mon Sep 17 00:00:00 2001 From: Olena Lisova Date: Thu, 28 Sep 2023 17:06:09 -0400 Subject: [PATCH 1/3] Done py_herbivores_and_carnivors --- app/main.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..3fb50b9a 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,36 @@ -# write your code here +class Animal: + alive = [] + + def __init__( + self, + name: str, + health: int = 100, + hidden: bool = False + ) -> None: + self.name = name + self.health = health + self.hidden = hidden + Animal.alive.append(self) + + def __repr__(self) -> str: + return "{Name:" \ + + f" {self.name}, Health: {self.health}, Hidden: {self.hidden}"\ + + "}" + + +class Herbivore(Animal): + def hide(self) -> None: + if self.hidden: + self.hidden = False + else: + self.hidden = True + + +class Carnivore(Animal): + def bite(self, animal: Herbivore) -> None: + if (animal in Animal.alive + and isinstance(animal, Herbivore) + and not animal.hidden): + animal.health -= 50 + if animal.health <= 0: + Animal.alive.remove(animal) From 5a1bda97eae7ba68bf590de3237a176a5a7feaba Mon Sep 17 00:00:00 2001 From: Olena Lisova Date: Fri, 29 Sep 2023 11:37:51 -0400 Subject: [PATCH 2/3] Changes has been made --- app/main.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index 3fb50b9a..551767b9 100644 --- a/app/main.py +++ b/app/main.py @@ -13,21 +13,19 @@ def __init__( Animal.alive.append(self) def __repr__(self) -> str: - return "{Name:" \ - + f" {self.name}, Health: {self.health}, Hidden: {self.hidden}"\ - + "}" + return ("{Name:" + + f" {self.name}, Health: {self.health}, Hidden: {self.hidden}" + + "}") class Herbivore(Animal): def hide(self) -> None: - if self.hidden: - self.hidden = False - else: - self.hidden = True + self.hidden = not self.hidden class Carnivore(Animal): - def bite(self, animal: Herbivore) -> None: + @staticmethod + def bite(animal: Herbivore) -> None: if (animal in Animal.alive and isinstance(animal, Herbivore) and not animal.hidden): From 2b4ec6062fef2ca8389ffd8cc48945bc139892d8 Mon Sep 17 00:00:00 2001 From: Olena Lisova Date: Mon, 2 Oct 2023 09:58:00 -0400 Subject: [PATCH 3/3] Changes has been made --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index 551767b9..64895840 100644 --- a/app/main.py +++ b/app/main.py @@ -13,9 +13,9 @@ def __init__( Animal.alive.append(self) def __repr__(self) -> str: - return ("{Name:" + - f" {self.name}, Health: {self.health}, Hidden: {self.hidden}" + - "}") + return ("{Name:" + + f" {self.name}, Health: {self.health}, Hidden: {self.hidden}" + + "}") class Herbivore(Animal):