-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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' #1579
base: master
Are you sure you want to change the base?
'Solution' #1579
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 implementing the Animal
, Carnivore
, and Herbivore
classes! 🎉 Your code meets the task requirements and constraints effectively. The class structure and inheritance are well done, and the methods are implemented correctly. The use of the alive
list as a class variable is appropriate for tracking all living animals, and your logic for the bite
and hide
methods aligns with the intended game mechanics.
Keep up the good work, and consider the feedback on the alive
list if you ever need to change the scope of tracking in future projects. Happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -1 +1,29 @@ | |||
# write your code here | |||
class Animal: | |||
alive = [] |
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.
The alive
list is a class variable, meaning it is shared across all instances of Animal
. If the intention is to track all living animals, this is correct. However, if each instance should have its own list, consider making it an instance variable instead.
|
||
class Carnivore(Animal): | ||
def bite(self, herbivore): | ||
if isinstance(herbivore, Herbivore) and not herbivore.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.
The condition not herbivore.hidden
is correctly checking if the herbivore is not hidden before allowing the carnivore to bite. Ensure that this logic aligns with the intended game mechanics.
if isinstance(herbivore, Herbivore) and not herbivore.hidden: | ||
herbivore.health -= 50 | ||
if herbivore.health <= 0: | ||
Animal.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.
Removing the herbivore from Animal.alive
when its health is less than or equal to zero is correct. Ensure that this logic is consistent with the intended behavior for when an animal 'dies'.
No description provided.