From 1cf63458b82ecddb31eeeb6051b830a538e9a812 Mon Sep 17 00:00:00 2001 From: Viktoria Rybenchuk Date: Fri, 10 Feb 2023 13:15:56 +0100 Subject: [PATCH 1/9] Solution --- app/main.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index fa56336e..f9b4eaf6 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,31 @@ -# 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 + Animal.alive.append(self) + + def __repr__(self) -> str: + name = self.name + health = self.health + hidden = self.hidden + return f"{{Name: {name}, Health: {health}, Hidden: {hidden}}}" + + +class Herbivore(Animal): + def hide(self) -> None: + self.hidden = not self.hidden + + +class Carnivore(Animal): + @staticmethod + def bite(herbivore: Herbivore) -> None: + if isinstance(herbivore, Herbivore) and herbivore.hidden is False: + herbivore.health -= 50 + if herbivore.health <= 0: + Animal.alive.remove(herbivore) From 53f2ac28859cdcc262edadb8ac458cfb5105bdb7 Mon Sep 17 00:00:00 2001 From: Viktoria Rybenchuk Date: Fri, 10 Feb 2023 14:10:44 +0100 Subject: [PATCH 2/9] Solution --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index f9b4eaf6..5d40e74a 100644 --- a/app/main.py +++ b/app/main.py @@ -4,7 +4,8 @@ class Animal: def __init__( self, name: str, health: int = 100, - hidden: bool = False) -> None: + hidden: bool = False + ) -> None: self.health = health self.name = name self.hidden = hidden @@ -23,8 +24,7 @@ def hide(self) -> None: class Carnivore(Animal): - @staticmethod - def bite(herbivore: Herbivore) -> None: + def bite(self, herbivore: Herbivore) -> None: if isinstance(herbivore, Herbivore) and herbivore.hidden is False: herbivore.health -= 50 if herbivore.health <= 0: From 5e9b69f65e0dab4c0831d55f1b8cf970f6d97a4f Mon Sep 17 00:00:00 2001 From: Viktoria Rybenchuk Date: Fri, 10 Feb 2023 14:53:34 +0100 Subject: [PATCH 3/9] Solution --- app/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index 5d40e74a..b011e976 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,8 @@ class Animal: alive = [] def __init__( - self, name: str, + self, + name: str, health: int = 100, hidden: bool = False ) -> None: @@ -12,10 +13,9 @@ def __init__( Animal.alive.append(self) def __repr__(self) -> str: - name = self.name - health = self.health - hidden = self.hidden - return f"{{Name: {name}, Health: {health}, Hidden: {hidden}}}" + return f"{{Name: {self.name}," \ + f" Health: {self.health}," \ + f" Hidden: {self.hidden}}}" class Herbivore(Animal): @@ -24,7 +24,8 @@ def hide(self) -> None: class Carnivore(Animal): - def bite(self, herbivore: Herbivore) -> None: + @staticmethod + def bite(herbivore: Herbivore) -> None: if isinstance(herbivore, Herbivore) and herbivore.hidden is False: herbivore.health -= 50 if herbivore.health <= 0: From 05a85b017004fa3bb1c8894fea9af33f583c5ed1 Mon Sep 17 00:00:00 2001 From: Viktoria Rybenchuk Date: Mon, 13 Feb 2023 13:50:02 +0100 Subject: [PATCH 4/9] Solution --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index b011e976..d2dc7fee 100644 --- a/app/main.py +++ b/app/main.py @@ -13,9 +13,9 @@ def __init__( Animal.alive.append(self) 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 1769e17ee17cd57c627e54cd50155ee8cdeff480 Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk Date: Thu, 24 Oct 2024 17:11:12 +0300 Subject: [PATCH 5/9] update README.md and checklist.md --- README.md | 2 +- checklist.md | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a119dd04..d88b6f0f 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Nature is well suited to reflect the principles of Object Oriented Programming. All instances of the `Animal` class must have health, name and hidden attribute. Health is 100 and hidden is false by default. -All alive animals should be in the class attribute `Animal.alive`. +All alive animals should be in the __class__ attribute `Animal.alive`. If the health of the animal reaches 0, the beast dies and it should be removed from `Animal.alive`. ```python diff --git a/checklist.md b/checklist.md index da6ede4e..e43887db 100644 --- a/checklist.md +++ b/checklist.md @@ -121,8 +121,25 @@ Bad example: def get_full_name(x: str, y: str) -> str: return f"{x} {y}" ``` +5. Place each argument on a new line, including `self`, with proper indentation and formatting + +Good example: + +```python +def __init__( + self, + name: str, + age: int +) -> None: +``` +Bad example: + +```python +def __init__(self, + name: str,age: int) -> None: +``` +6. It's good practice to specify type annotations for clarity, such as using `list[Animal]` instead of `list` to indicate a list of Animal instances ## Clean Code -Add comments, prints, and functions to check your solution when you write your code. -Don't forget to delete them when you are ready to commit and push your code. +1. No need to add comments if the code is clear and self-explanatory From 08bd49d176426a80f9fd6efc328b813f9fd4de55 Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk Date: Thu, 24 Oct 2024 17:15:57 +0300 Subject: [PATCH 6/9] rollback main.py --- app/main.py | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/app/main.py b/app/main.py index d2dc7fee..fa56336e 100644 --- a/app/main.py +++ b/app/main.py @@ -1,32 +1 @@ -class Animal: - alive = [] - - def __init__( - self, - name: str, - health: int = 100, - hidden: bool = False - ) -> None: - self.health = health - self.name = name - 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(herbivore: Herbivore) -> None: - if isinstance(herbivore, Herbivore) and herbivore.hidden is False: - herbivore.health -= 50 - if herbivore.health <= 0: - Animal.alive.remove(herbivore) +# write your code here From 56573c034361af88a2e03cb429c45142f5991eb3 Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk <122517203+viktoria-rybenchuk@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:26:42 +0300 Subject: [PATCH 7/9] fix: __class__ vs __ markdown format Co-authored-by: Sergii Nosachenko <54940595+sergii-nosachenko@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d88b6f0f..5b58b7e6 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Nature is well suited to reflect the principles of Object Oriented Programming. All instances of the `Animal` class must have health, name and hidden attribute. Health is 100 and hidden is false by default. -All alive animals should be in the __class__ attribute `Animal.alive`. +All alive animals should be in the `__class__` attribute `Animal.alive`. If the health of the animal reaches 0, the beast dies and it should be removed from `Animal.alive`. ```python From 583f3945e467aad122d1cfbcb6c0dc390982da1f Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk <122517203+viktoria-rybenchuk@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:27:52 +0300 Subject: [PATCH 8/9] cleanup type hints documentation Co-authored-by: Sergii Nosachenko <54940595+sergii-nosachenko@users.noreply.github.com> --- checklist.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/checklist.md b/checklist.md index e43887db..16573962 100644 --- a/checklist.md +++ b/checklist.md @@ -139,7 +139,8 @@ def __init__(self, name: str,age: int) -> None: ``` -6. It's good practice to specify type annotations for clarity, such as using `list[Animal]` instead of `list` to indicate a list of Animal instances +6. It's important to use type annotations for clarity, such as `list[Animal]` instead of just `list` to specify a list of Animal instances + ## Clean Code 1. No need to add comments if the code is clear and self-explanatory From 3198e228183a70526fe97c2a08c2368740258f63 Mon Sep 17 00:00:00 2001 From: Viktoriia Rybenchuk <122517203+viktoria-rybenchuk@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:28:37 +0300 Subject: [PATCH 9/9] simplify comment Co-authored-by: Sergii Nosachenko <54940595+sergii-nosachenko@users.noreply.github.com> --- checklist.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checklist.md b/checklist.md index 16573962..aa5f2472 100644 --- a/checklist.md +++ b/checklist.md @@ -143,4 +143,4 @@ def __init__(self, ## Clean Code -1. No need to add comments if the code is clear and self-explanatory +1. There’s no need to add comments if the code is clear and self-explanatory.