-
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 #1634
base: master
Are you sure you want to change the base?
solution #1634
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 with all the required methods! 🎉 Your code meets the task requirements and constraints effectively. While returning NotImplemented
is correct for unsupported operations, consider using a TypeError
with a descriptive message for better error handling in the future. Keep up the excellent work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
return Distance(self.km + other.km) | ||
elif isinstance(other, (int, float)): | ||
return Distance(self.km + other) | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
elif isinstance(other, (int, float)): | ||
self.km += other | ||
else: | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
def __mul__(self, other: int | float) -> "Distance": | ||
if isinstance(other, (int, float)): | ||
return Distance(self.km * other) | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
def __truediv__(self, other: int | float) -> "Distance": | ||
if isinstance(other, (int, float)) and other != 0: | ||
return Distance(round(self.km / other, 2)) | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
return self.km < other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km < other | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
return self.km > other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km > other | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
return self.km == other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km == other | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
return self.km <= other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km <= other | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
return self.km >= other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km >= other | ||
return NotImplemented |
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.
Returning NotImplemented
is appropriate when the operation is not supported for the given type. However, consider raising a TypeError
with a descriptive message for better error handling and debugging.
No description provided.