From 0142b28cb4d1cd23b5a66bca2196f281ed6b24e3 Mon Sep 17 00:00:00 2001 From: Trukhanov Danylo Date: Sat, 7 Dec 2024 18:08:50 +0200 Subject: [PATCH 1/5] Solution --- app/main.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..de585611 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,35 @@ -# 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 ( + f"{{Name: {self.name}, " + f"Health: {self.health}, " + f"Hidden: {self.hidden}}}" + ) + + +class Herbivore(Animal): + def hide(self) -> None: + self.hidden = not self.hidden + + +class Carnivore(Animal): + @staticmethod + def bite(victim: Herbivore) -> None: + if victim.hidden or isinstance(victim, Carnivore): + return + victim.health -= 50 + if victim.health <= 0: + Animal.alive.remove(victim) From 02f34506d4403adf324b91f3fd53760c10218c34 Mon Sep 17 00:00:00 2001 From: Trukhanov Danylo Date: Sat, 7 Dec 2024 19:35:36 +0200 Subject: [PATCH 2/5] Solution --- app/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/main.py b/app/main.py index de585611..011dd32a 100644 --- a/app/main.py +++ b/app/main.py @@ -30,6 +30,8 @@ class Carnivore(Animal): def bite(victim: Herbivore) -> None: if victim.hidden or isinstance(victim, Carnivore): return + victim.health -= 50 + if victim.health <= 0: Animal.alive.remove(victim) From ad4a584d1433af1ec2fd2d437c0c3ffa08b92434 Mon Sep 17 00:00:00 2001 From: Trukhanov Danylo Date: Sat, 7 Dec 2024 19:42:03 +0200 Subject: [PATCH 3/5] Solution --- app/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/main.py b/app/main.py index 011dd32a..b2795269 100644 --- a/app/main.py +++ b/app/main.py @@ -30,7 +30,6 @@ class Carnivore(Animal): def bite(victim: Herbivore) -> None: if victim.hidden or isinstance(victim, Carnivore): return - victim.health -= 50 if victim.health <= 0: From 13df3430f0062091ac5f25f557656bb3894a88aa Mon Sep 17 00:00:00 2001 From: Trukhanov Danylo Date: Sun, 8 Dec 2024 10:15:52 +0200 Subject: [PATCH 4/5] Solution --- app/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/main.py b/app/main.py index b2795269..de585611 100644 --- a/app/main.py +++ b/app/main.py @@ -31,6 +31,5 @@ def bite(victim: Herbivore) -> None: if victim.hidden or isinstance(victim, Carnivore): return victim.health -= 50 - if victim.health <= 0: Animal.alive.remove(victim) From eafebe37219372ffad19c54dc6c8850280a364d4 Mon Sep 17 00:00:00 2001 From: Trukhanov Danylo Date: Mon, 9 Dec 2024 14:06:45 +0200 Subject: [PATCH 5/5] just trying hoping for a successful review --- app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/main.py b/app/main.py index de585611..1c7bea38 100644 --- a/app/main.py +++ b/app/main.py @@ -30,6 +30,7 @@ class Carnivore(Animal): def bite(victim: Herbivore) -> None: if victim.hidden or isinstance(victim, Carnivore): return + victim.health -= 50 if victim.health <= 0: Animal.alive.remove(victim)