Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Darya-Savchenko
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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

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

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

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

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

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

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

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

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants