-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #1658
base: master
Are you sure you want to change the base?
Solution #1658
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 Distance
class! 🎉 The core functionality is solid, and you've met the task requirements. Just a couple of minor improvements: ensure the type hints include int
and float
for better clarity, and handle division by zero with an exception. Keep up the great work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
# / | ||
def __truediv__(self, other: int | float) -> Distance: | ||
if other == 0: | ||
return Distance(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.
The __truediv__
method should raise an exception when dividing by zero instead of returning a Distance
object with zero. Consider using raise ZeroDivisionError('division by zero')
.
return Distance(km=result) | ||
|
||
def __lt__(self, other: Distance) -> bool: | ||
if isinstance(other, (int, 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.
The type hint for the other
parameter should include int
and float
as well as Distance
. Update it to other: Distance | int | float
.
return self.km < other.km | ||
|
||
def __gt__(self, other: Distance) -> bool: | ||
if isinstance(other, (int, 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.
The type hint for the other
parameter should include int
and float
as well as Distance
. Update it to other: Distance | int | float
.
return self.km > other.km | ||
|
||
def __eq__(self, other: Distance) -> bool: | ||
if isinstance(other, (int, 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.
The type hint for the other
parameter should include int
and float
as well as Distance
. Update it to other: Distance | int | float
.
return self.km == other.km | ||
|
||
def __le__(self, other: Distance) -> bool: | ||
if isinstance(other, (int, 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.
The type hint for the other
parameter should include int
and float
as well as Distance
. Update it to other: Distance | int | float
.
return self.km <= other.km | ||
|
||
def __ge__(self, other: Distance) -> bool: | ||
if isinstance(other, (int, 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.
The type hint for the other
parameter should include int
and float
as well as Distance
. Update it to other: Distance | int | float
.
No description provided.