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 #1672

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

Solution #1672

wants to merge 2 commits into from

Conversation

sessd
Copy link

@sessd sessd commented Jan 9, 2025

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 this implementation! 😊 There are a few critical issues that need to be addressed to ensure the functionality of the Distance class is correct:

  1. Comparison Methods: The comparison methods (__lt__, __gt__, __eq__, __le__, __ge__) currently have incorrect logic when comparing Distance objects. Make sure to compare the km attributes of the Distance objects (e.g., self.km < other.km) rather than comparing the object itself.

  2. Return Types: The return types for the comparison methods should be bool, not float. These methods should return a boolean value indicating the result of the comparison.

  3. Division by Zero: Ensure that the __truediv__ method checks for division by zero to prevent runtime errors.

Once these issues are resolved, your code will be in great shape! Keep up the great work, and don't hesitate to reach out if you have any questions or 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
result_km = round(self.km / other, 2)
return Distance(result_km)

def __lt__(self, other: float) -> float:

Choose a reason for hiding this comment

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

The return type of __lt__ should be bool, not float. This method should return a boolean indicating if the current instance is less than the other.

app/main.py Outdated
Comment on lines 39 to 40
if isinstance(other, Distance):
return self.km < other

Choose a reason for hiding this comment

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

When comparing with another Distance object, you should compare self.km < other.km instead of self.km < other.

app/main.py Outdated
if isinstance(other, Distance):
return self.km < other

def __gt__(self, other: float) -> float:

Choose a reason for hiding this comment

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

The return type of __gt__ should be bool, not float. This method should return a boolean indicating if the current instance is greater than the other.

app/main.py Outdated
Comment on lines 45 to 46
if isinstance(other, Distance):
return self.km > other

Choose a reason for hiding this comment

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

When comparing with another Distance object, you should compare self.km > other.km instead of self.km > other.

app/main.py Outdated
if isinstance(other, Distance):
return self.km > other

def __eq__(self, other: float) -> float:

Choose a reason for hiding this comment

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

The return type of __eq__ should be bool, not float. This method should return a boolean indicating if the current instance is equal to the other.

app/main.py Outdated
Comment on lines 51 to 52
if isinstance(other, Distance):
return self.km == other

Choose a reason for hiding this comment

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

When comparing with another Distance object, you should compare self.km == other.km instead of self.km == other.

app/main.py Outdated
if isinstance(other, Distance):
return self.km == other

def __le__(self, other: float) -> float:

Choose a reason for hiding this comment

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

The return type of __le__ should be bool, not float. This method should return a boolean indicating if the current instance is less than or equal to the other.

app/main.py Outdated
Comment on lines 57 to 58
if isinstance(other, Distance):
return self.km <= other

Choose a reason for hiding this comment

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

When comparing with another Distance object, you should compare self.km <= other.km instead of self.km <= other.

app/main.py Outdated
if isinstance(other, Distance):
return self.km <= other

def __ge__(self, other: float) -> float:

Choose a reason for hiding this comment

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

The return type of __ge__ should be bool, not float. This method should return a boolean indicating if the current instance is greater than or equal to the other.

app/main.py Outdated
Comment on lines 63 to 64
if isinstance(other, Distance):
return self.km >= other

Choose a reason for hiding this comment

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

When comparing with another Distance object, you should compare self.km >= other.km instead of self.km >= other.

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 effort on implementing the Distance class! 🎉 While your solution is on the right track, there are a few important issues that need attention to ensure the class functions correctly and adheres to the task requirements:

  1. Constructor Type Annotation: The __init__ method should have the parameter km annotated as float or int instead of bool. This will ensure that the class handles distance values appropriately.

  2. Division by Zero Check: In the __truediv__ method, it's crucial to add a check to prevent division by zero. This will help avoid runtime errors and make your code more robust.

  3. Comparison Methods Type Annotations: The parameter other in the comparison methods (__lt__, __gt__, __eq__, __le__, __ge__) should be annotated as Distance, int, or float, not bool. This will ensure that comparisons are made correctly.

These issues are important for the functionality of your code, so please take the time to review and address them. Remember, learning from these improvements will help you grow as a developer. Keep up the good work, and don't hesitate to reach out if you have any questions! 😊

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

class Distance:
# Write your code here
pass
def __init__(self, km: bool) -> None:

Choose a reason for hiding this comment

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

The constructor parameter km should be of type float or int, not bool. This is likely a mistake in the type annotation.

Comment on lines +31 to +34
def __truediv__(self, other: Distance) -> Distance:
if isinstance(other, (int, float)):
result_km = round(self.km / other, 2)
return Distance(result_km)

Choose a reason for hiding this comment

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

The __truediv__ method should include a check to prevent division by zero when other is zero. This will prevent runtime errors.

result_km = round(self.km / other, 2)
return Distance(result_km)

def __lt__(self, other: bool) -> bool:

Choose a reason for hiding this comment

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

The parameter other in the comparison methods should be of type Distance, int, or float, not bool. This is likely a mistake in the type annotation.

if isinstance(other, Distance):
return self.km < other.km

def __gt__(self, other: bool) -> bool:

Choose a reason for hiding this comment

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

The parameter other in the comparison methods should be of type Distance, int, or float, not bool. This is likely a mistake in the type annotation.

if isinstance(other, Distance):
return self.km > other.km

def __eq__(self, other: bool) -> bool:

Choose a reason for hiding this comment

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

The parameter other in the comparison methods should be of type Distance, int, or float, not bool. This is likely a mistake in the type annotation.

if isinstance(other, Distance):
return self.km == other.km

def __le__(self, other: bool) -> bool:

Choose a reason for hiding this comment

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

The parameter other in the comparison methods should be of type Distance, int, or float, not bool. This is likely a mistake in the type annotation.

if isinstance(other, Distance):
return self.km <= other.km

def __ge__(self, other: bool) -> bool:

Choose a reason for hiding this comment

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

The parameter other in the comparison methods should be of type Distance, int, or float, not bool. This is likely a mistake in the type annotation.

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