Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Carnivores and Herbivores Solution #728

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Lyutillis
Copy link

No description provided.

@@ -129,6 +129,8 @@ def test_print_animal_alive():

f = io.StringIO()

print(Animal.alive)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont change the tests))

app/main.py Outdated
Comment on lines 27 to 31
if herbivore.hidden or isinstance(herbivore, Carnivore):
return
herbivore.health = max(0, herbivore.health - 50)
if not herbivore.health:
Animal.alive.pop(Animal.alive.index(herbivore))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we resolve it a little bit simpler?

app/main.py Outdated


class Carnivore(Animal):
def bite(self, herbivore: Herbivore) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need self here, so make this method static

app/main.py Outdated
Comment on lines 14 to 17
name = f"Name: {self.name}, "
health = f"Health: {self.health}, "
hidden = f"Hidden: {self.hidden}"
return "{" + name + health + hidden + "}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite with only return, use f-strings

app/main.py Outdated

class Carnivore(Animal):
@staticmethod
def bite(herbivore: Herbivore) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix annotations and variable name, if this method would take only Herbivore instances, you won't need a check in the next line

app/main.py Outdated
Comment on lines 28 to 29
if herbivore.hidden or isinstance(herbivore, Carnivore):
return

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use the opposite condition

app/main.py Outdated
return
herbivore.health -= 50
if herbivore.health <= 0:
Animal.alive.pop(Animal.alive.index(herbivore))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u can use .remove(value)

app/main.py Outdated
Comment on lines 14 to 16
return f"{{Name: {self.name}, " \
f"Health: {self.health}, " \
f"Hidden: {self.hidden}}}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use brackets instead of linebreaker here

app/main.py Outdated
class Carnivore(Animal):
@staticmethod
def bite(herbivore: Animal) -> None:
if not (herbivore.hidden or isinstance(herbivore, Carnivore)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if later there will be another class that inherits from Animal? You should fix this condition, so it will be True only with Herbivore instance

app/main.py Outdated

class Carnivore(Animal):
@staticmethod
def bite(herbivore: Animal) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix variable name, it is not descriptive now, you use it not only for herbivores

app/main.py Outdated

class Carnivore(Animal):
@staticmethod
def bite(herbivore: Herbivore | Carnivore) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Animal for annotations here and fix parameter name, it is not descriptive now

Copy link

@fsocie7y fsocie7y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants