-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 #1298
base: master
Are you sure you want to change the base?
Solution #1298
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.
Great job on your code! 🎉 There are a few areas that could be improved for efficiency and cleanliness, but these are minor issues and do not impact the core functionality of your code. Keep up the good work and consider the provided feedback for your future coding tasks. Happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
class Carnivore(Animal): | ||
@classmethod | ||
def bite(cls, herbivore: Animal) -> 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.
Code Efficiency: You should use the class name to get access to the class attributes. In this case, instead of cls.alive.remove(herbivore)
, you should use Animal.alive.remove(herbivore)
. Refer to point 1 in the checklist.
|
||
class Herbivore(Animal): | ||
def hide(self) -> None: | ||
self.hidden = not self.hidden |
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.
Code Efficiency: You can change the bool
value in one line without using an if
statement. In this case, you should use self.hidden = not self.hidden
. Refer to point 2 in the checklist.
def bite(cls, herbivore: Animal) -> None: | ||
if isinstance(herbivore, Herbivore) and not herbivore.hidden: | ||
herbivore.health -= 50 | ||
|
||
if herbivore.health <= 0: | ||
cls.alive.remove(herbivore) |
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.
Code Efficiency: This method could be a static method since it doesn't use any instance attributes. Refer to point 3 in the checklist.
def __repr__(self) -> str: | ||
return (f"{{Name: {self.name}, " | ||
f"Health: {self.health}, " | ||
f"Hidden: {self.hidden}}}") |
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.
Code Style: You should use interpolation instead of concatenation. In this case, instead of f"{{Name: {self.name}, "
, you should use f"{{Name: {self.name}, "
. Refer to point 3 in the checklist.
def __init__(self, | ||
name: str, | ||
heals: int = 100, | ||
hidden: bool = False) -> None: | ||
self.name = name | ||
self.health = heals | ||
self.hidden = hidden |
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.
Code Style: You should use descriptive and correct variable names. In this case, instead of heals
, you should use health
. Refer to point 4 in the checklist.
No description provided.