From e983c5aad5ff5a1a7b63118f7785af957d490b29 Mon Sep 17 00:00:00 2001 From: AbsoluteProgramist <108784501+maksimpro001@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:15:39 +0300 Subject: [PATCH 1/3] Update main.py --- app/main.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..afbddb75 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,39 @@ -# 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 __setattr__(self, attr: str, value: int) -> None: + if attr == "health" and value <= 0 and self in Animal.alive: + Animal.alive.remove(self) + super().__setattr__(attr, value) + + def __repr__(self) -> str: + return f"{{Name: {self.name}, " \ + f"Health: {self.health}, " \ + f"Hidden: {self.hidden}}}" + + +class Herbivore(Animal): + def hide(self) -> bool: + if self.hidden is False: + self.hidden = True + else: + self.hidden = False + return self.hidden + + +class Carnivore(Animal): + @staticmethod + def bite(other: "Animal") -> int: + if isinstance(other, Herbivore) and not other.hidden: + other.health -= 50 + return other.health From ca5da8e111226a8efe00bc8426ac56a534d99c9b Mon Sep 17 00:00:00 2001 From: AbsoluteProgramist <108784501+maksimpro001@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:42:33 +0300 Subject: [PATCH 2/3] Update main.py --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index afbddb75..d4d941e8 100644 --- a/app/main.py +++ b/app/main.py @@ -17,9 +17,9 @@ def __setattr__(self, attr: str, value: int) -> None: super().__setattr__(attr, value) def __repr__(self) -> str: - return f"{{Name: {self.name}, " \ - f"Health: {self.health}, " \ - f"Hidden: {self.hidden}}}" + return (f"{{Name: {self.name}, " + + f"Health: {self.health}, " + + f"Hidden: {self.hidden}}}") class Herbivore(Animal): From 8cb03727196299842e9f066386fea8d20e01b9ce Mon Sep 17 00:00:00 2001 From: AbsoluteProgramist <108784501+maksimpro001@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:46:34 +0300 Subject: [PATCH 3/3] Update main.py --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index d4d941e8..c02d3b40 100644 --- a/app/main.py +++ b/app/main.py @@ -17,9 +17,9 @@ def __setattr__(self, attr: str, value: int) -> None: super().__setattr__(attr, value) def __repr__(self) -> str: - return (f"{{Name: {self.name}, " + - f"Health: {self.health}, " + - f"Hidden: {self.hidden}}}") + return (f"{{Name: {self.name}, " + f"Health: {self.health}, " + f"Hidden: {self.hidden}}}") class Herbivore(Animal):