-
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' #1397
base: master
Are you sure you want to change the base?
'Solution' #1397
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.
Everything is all right but you can simplify bite method by using and statement
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: 4]
Additional info:
Ignored files list:
app/main.py
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: 4]
Additional info:
Ignored files list:
app/main.py
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: 4]
Additional info:
Ignored files list:
app/main.py
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
There are no files to review. Please make sure that you have added files to the pull request. Some files and directories may be ignored from the review or failed to load.
[CODE: 4]
Additional info:
Ignored files list:
app/main.py
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
app/main.py
Outdated
if not self.hidden: | ||
self.hidden = True | ||
return | ||
self.hidden = False |
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 can be a one-liner, please read a checklist!
app/main.py
Outdated
class Carnivore(Animal): | ||
|
||
@staticmethod | ||
def bite(other: Union[Carnivore, Herbivore]) -> Union[str, 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.
You can simply use str | None, without Union, it's not needed here
app/main.py
Outdated
return "Carnivore won't bit Carnivore" | ||
if isinstance(other, Herbivore) and other.hidden: | ||
return "Carnivore won't be able to bite hidden Herbivore" | ||
if other.health > 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.
Do you need this check? Every bite it is -50,it looks like not required here
app/main.py
Outdated
def __str__(self) -> str: | ||
|
||
return (f"Name: {self.name}, " | ||
f"Health: {self.health}, " | ||
f"Hidden: {self.hidden}") | ||
|
||
def __repr__(self) -> str: | ||
|
||
return f"{{{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.
It looks like you need to use only repr
app/main.py
Outdated
if isinstance(other, Carnivore): | ||
return "Carnivore won't bit Carnivore" | ||
if isinstance(other, Herbivore) and other.hidden: | ||
return "Carnivore won't be able to bite hidden 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.
At task we don't have requirements to return some text.
Carnivore has a bite method, which takes a herbivore object and decreases the object's health by 50. The method does not work if it is another сarnivore, or the herbivore is currently hiding.
app/main.py
Outdated
if isinstance(other, Carnivore): | ||
return | ||
if isinstance(other, Herbivore) and other.hidden: | ||
return | ||
other.health -= 50 | ||
if other.health <= 0: | ||
Animal.alive.pop(Animal.alive.index(other)) |
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.
at task you need to check only for is other instance of Herbivore and not hidden.
So you don't need return at all, simplify this method
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 method does not work if it is another сarnivore, or the herbivore is currently hiding. This is from condition of the task
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.
So I finally understand what exactly did you mean
app/main.py
Outdated
if isinstance(other, Carnivore): | ||
return | ||
if isinstance(other, Herbivore) and other.hidden: | ||
return | ||
other.health -= 50 | ||
if other.health <= 0: | ||
Animal.alive.pop(Animal.alive.index(other)) |
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.
Also at 37 line Animal.alive.pop(Animal.alive.index(other))
Simplify this line. We access class attributes through class name and it's better to use remove when value is given and del when an index is given. You do unnecessary work here
app/main.py
Outdated
class Carnivore(Animal): | ||
|
||
@staticmethod | ||
def bite(other: Union[Carnivore, 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.
at can be simlified to Animal, as all of them is child of Animal, don't needed Union
app/main.py
Outdated
return (f"{{" | ||
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.
If you have already put these brackets in a separate line, do the same at the end, or vice versa.
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.
Nice! 😎
No description provided.