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

Solution #679

Closed
wants to merge 5 commits into from
Closed

Solution #679

wants to merge 5 commits into from

Conversation

PyCore23
Copy link

No description provided.

Copy link

@Dimosphen1 Dimosphen1 left a comment

Choose a reason for hiding this comment

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

Several changes were requested.

app/main.py Outdated
Comment on lines 30 to 31
target.health -= 50 \
if (isinstance(target, Herbivore) and not target.hidden) else 0

Choose a reason for hiding this comment

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

Write this code in multiple lines to avoid line-breaking with \. Besides that, if the target is an instance of Carnivore, or it is hidden its health would always equal 0 in your current version.

app/main.py Outdated

class Carnivore(Animal):

def bite(self, target: Union) -> None:

Choose a reason for hiding this comment

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

Change your type annotation for the target to indicate that you expect a Herbivore instance.

app/main.py Outdated
def bite(self, target: Union) -> None:
target.health -= 50 \
if (isinstance(target, Herbivore) and not target.hidden) else 0
Animal.remove_dead_animal()

Choose a reason for hiding this comment

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

It would be inefficient to make a perform list comprehension and create a new list each time after the animal is deleted from the alive. Use .remove(target) to perform deletion in place and implement this logic inside of the bite method, delete the remove_dead_animal class method from the Animal class.

app/main.py Outdated
self.name = name
self.health = health
self.hidden = hidden
self.alive.append(self)

Choose a reason for hiding this comment

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

Refer to Animal.alive instead of self.alive, because alive is a class attribute.

Choose a reason for hiding this comment

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

not fixed

app/main.py Outdated
@@ -1 +1,38 @@
# write your code here
from typing import Union

Choose a reason for hiding this comment

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

Do not forget to remove unnecessary imports.

app/main.py Outdated
self,
name: str,
health: int = 100,
hidden: bool = False) -> None:

Choose a reason for hiding this comment

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

Place ) -> None: on a new line to format your code properly.

@PyCore23 PyCore23 requested a review from Dimosphen1 October 17, 2023 20:08
app/main.py Outdated
self.name = name
self.health = health
self.hidden = hidden
self.alive.append(self)

Choose a reason for hiding this comment

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

not fixed

@PyCore23 PyCore23 requested a review from pavlejviki October 22, 2023 18:35
app/main.py Outdated
self.name = name
self.health = health
self.hidden = hidden
self.alive.append(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Append the current instance to the class attribute 'alive'

app/main.py Outdated
self.alive.append(self)

@classmethod
def remove_dead_animal(cls, animal: Type[Herbivore]) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def remove_dead_animal(cls, animal: Type[Herbivore]) -> None:
def remove_dead_animal(cls, animal: Herbivore) -> None:

Copy link

@pavlejviki pavlejviki 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!

@PyCore23 PyCore23 closed this by deleting the head repository May 17, 2024
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.

4 participants