-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Solution #679
Conversation
There was a problem hiding this 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
target.health -= 50 \ | ||
if (isinstance(target, Herbivore) and not target.hidden) else 0 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
app/main.py
Outdated
self.name = name | ||
self.health = health | ||
self.hidden = hidden | ||
self.alive.append(self) |
There was a problem hiding this comment.
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
self.name = name | ||
self.health = health | ||
self.hidden = hidden | ||
self.alive.append(self) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def remove_dead_animal(cls, animal: Type[Herbivore]) -> None: | |
def remove_dead_animal(cls, animal: Herbivore) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done!
No description provided.