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' #1685

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

'Solution' #1685

wants to merge 2 commits into from

Conversation

viktoriaom
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.


Thank you for your hard work on implementing the Distance class! 🚀 While your code is mostly on the right track, there are some critical issues with the comparison methods that need to be addressed before we can approve the pull request.

Key Issues to Address:

  1. Comparison Methods:

    • The methods __lt__, __gt__, __eq__, __le__, and __ge__ need to handle comparisons with both Distance objects and numeric types (int, float).
    • Currently, the logic for comparing Distance objects is either missing or incorrect. Ensure that you check if other is an instance of Distance and compare self.km with other.km in such cases.
  2. Type Annotations:

    • Update the type annotations for these methods to reflect that they should accept both Distance instances and numeric types.

Once these issues are resolved, your implementation will be much stronger and fully compliant with the task requirements. Keep up the great work, and don't hesitate to reach out if you need further assistance! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

app/main.py Outdated
Comment on lines 32 to 33
def __lt__(self, other: Distance) -> bool:
return self.km < other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __lt__ method should handle comparisons with both Distance objects and numeric types (int, float). Currently, it only compares with numeric types. You should check if other is an instance of Distance and compare self.km with other.km in that case.

app/main.py Outdated
Comment on lines 35 to 36
def __gt__(self, other: Distance | int | float) -> bool:
return self.km > other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __gt__ method should handle comparisons with both Distance objects and numeric types (int, float). Ensure you check if other is an instance of Distance and compare self.km with other.km if so.

app/main.py Outdated
Comment on lines 38 to 39
def __eq__(self, other: Distance) -> bool:
return self.km == other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __eq__ method should handle comparisons with both Distance objects and numeric types (int, float). Currently, it only compares with numeric types. You should check if other is an instance of Distance and compare self.km with other.km in that case.

app/main.py Outdated
Comment on lines 41 to 42
def __le__(self, other: Distance) -> bool:
return self.km <= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __le__ method should handle comparisons with both Distance objects and numeric types (int, float). Ensure you check if other is an instance of Distance and compare self.km with other.km if so.

app/main.py Outdated
Comment on lines 44 to 45
def __ge__(self, other: Distance) -> bool:
return self.km >= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __ge__ method should handle comparisons with both Distance objects and numeric types (int, float). Ensure you check if other is an instance of Distance and compare self.km with other.km if so.

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.

Review Summary

Great job on implementing the Distance class! 🎉 Your solution meets the task requirements and constraints, with correct initialization, representation, arithmetic operations, and comparison methods. The use of type annotations is also well done.

However, there's a critical issue with the __truediv__ method: it currently does not handle division by zero, which could lead to runtime errors. Please ensure to add a check for division by zero to prevent potential crashes.

Despite this, your implementation is approved to help you move forward with your learning journey. Please review the comments and address the division by zero issue in future iterations to enhance the robustness of your code. Keep up the good work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +29 to +30
def __truediv__(self, other: int | float) -> Distance:
return Distance(round(self.km / other, 2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __truediv__ method does not handle division by zero, which can lead to a ZeroDivisionError. Consider adding a check to ensure other is not zero before performing the division.

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