-
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' #1222
base: master
Are you sure you want to change the base?
'Solution' #1222
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
def __init__(self, | ||
name: str, | ||
is_hungry: bool = True | ||
) -> 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 each argument including self
on a new line so that there would be no arguments on the same line with opening and closing parenthesis here and in the Dog
class as well. It will help to improve the code style and readability
app/main.py
Outdated
print(f"Eating {self.appetite} food points...") | ||
self.is_hungry = False | ||
return self.appetite | ||
else: |
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.
There is no need for else
since the code will not execute after the return
statement anyway. Please, remove the redundant else
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.
app/main.py
Outdated
def __init__( | ||
self, | ||
name: str, | ||
appetite: float, |
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.
appetite
could be int
as well, add it to the type annotation
app/main.py
Outdated
total_food_points = 0 | ||
for animal in animals: | ||
if animal.is_hungry: | ||
total_food_points += animal.feed() | ||
return total_food_points |
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.
Implement this method in one line using sum
. There is no need to check if animal is hungry here since it is done in the feed
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.
Several changes were requested
app/main.py
Outdated
else: | ||
return 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.
Please, remove the redundant else
and leave the return statement
else: | |
return 0 | |
return 0 |
app/main.py
Outdated
|
||
|
||
def feed_animals(animals: list[Animal]) -> int: | ||
return sum(animal.feed() for animal in animals if animal.is_hungry) |
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.
There is no need to perform the if check here, it is already done in the feed
method
return sum(animal.feed() for animal in animals if animal.is_hungry) | |
return sum(animal.feed() for animal in animals) |
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.
LGTM, well done!
No description provided.