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

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

Solution #1641

wants to merge 2 commits into from

Conversation

Jk-frontEnd
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 this pull request! 😊 However, there are a few critical issues that need to be addressed before we can approve it.

  1. Type Checking in Methods: The __truediv__, __mul__, and __iadd__ methods assume that other is a numeric type without proper type checking. It's important to verify if other is an instance of Distance or a numeric type before performing operations to avoid potential errors.

  2. __truediv__ Method Logic: The round function is not modifying self.km as intended. You should assign the result of round(self.km, 2) back to self.km to ensure the value is correctly rounded.

  3. __repr__ Method Bug: The __repr__ method references an undefined attribute self.distance. This should be corrected to self.km to accurately represent the object's state.

These issues are crucial as they impact the functionality and correctness of the Distance class. Once these are resolved, your code will be much stronger and ready for approval. Keep up the great work, and don't hesitate to reach out if you need any help! 🚀

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

return f"Distance: {self.km} kilometers."

def __repr__(self):
return f"Distance(km={self.distance})"

Choose a reason for hiding this comment

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

The __repr__ method references self.distance, which is not defined. It should be self.km to correctly represent the object's state.

Comment on lines +19 to +22
if not isinstance(other, Distance):
raise TypeError("Can only add Distance or numeric types.")

self.km += other

Choose a reason for hiding this comment

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

In the __iadd__ method, the code assumes other is a numeric type without checking. You should check if other is an instance of Distance or a numeric type before performing the addition.

Comment on lines +28 to +31
if not isinstance(other, Distance):
raise TypeError("Can only multiply Distance or numeric types.")

self.km *= other

Choose a reason for hiding this comment

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

In the __mul__ method, the code assumes other is a numeric type without checking. You should check if other is an instance of Distance or a numeric type before performing the multiplication.

Comment on lines +36 to +40
if not isinstance(other, Distance):
raise TypeError("Can only divide Distance or numeric types.")

self.km /= other
round(self.km, 2)

Choose a reason for hiding this comment

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

In the __truediv__ method, the code assumes other is a numeric type without checking. Additionally, the round function does not modify self.km as intended. You should assign the result of round(self.km, 2) back to self.km.

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 effort on implementing the Distance class! 🚀 While your code is on the right track, there are a few critical issues that need attention to ensure it functions as intended:

  1. Type Checking in Methods: The __iadd__, __mul__, and __truediv__ methods should allow operations with both Distance instances and numeric types (int or float). Currently, they only check for Distance instances, which can lead to TypeError when using numeric types.

  2. __truediv__ Method Logic: The rounding operation in the __truediv__ method is not affecting self.km because the result of round(self.km, 2) is not assigned back to self.km. Make sure to update self.km with the rounded value.

  3. __repr__ Method Bug: The __repr__ method incorrectly references self.distance instead of self.km, which will cause an AttributeError. Update it to use self.km to accurately represent the object's state.

These issues are important for the functionality of your code, so please review and address them. Remember, addressing these will not only improve your current implementation but also enhance your coding skills for future projects. 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! ✨

return f"Distance: {self.km} kilometers."

def __repr__(self):
return f"Distance(km={self.distance})"

Choose a reason for hiding this comment

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

The __repr__ method references an undefined attribute self.distance. It should be self.km to accurately represent the object's state.


def __iadd__(self, other):
if not isinstance(other, Distance):
raise TypeError("Can only add Distance or numeric types.")

Choose a reason for hiding this comment

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

The type checking in the __iadd__ method should allow numeric types as well. Consider checking if other is an instance of Distance or a numeric type.

if not isinstance(other, Distance):
raise TypeError("Can only add Distance or numeric types.")

self.km += other

Choose a reason for hiding this comment

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

The __iadd__ method assumes other is numeric without proper type checking. Ensure other is either a Distance instance or a numeric type before performing the operation.


def __mul__(self, other):
if not isinstance(other, Distance):
raise TypeError("Can only multiply Distance or numeric types.")

Choose a reason for hiding this comment

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

The type checking in the __mul__ method should allow numeric types as well. Consider checking if other is an instance of Distance or a numeric type.

if not isinstance(other, Distance):
raise TypeError("Can only multiply Distance or numeric types.")

self.km *= other

Choose a reason for hiding this comment

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

The __mul__ method assumes other is numeric without proper type checking. Ensure other is either a Distance instance or a numeric type before performing the operation.


def __truediv__(self, other):
if not isinstance(other, Distance):
raise TypeError("Can only divide Distance or numeric types.")

Choose a reason for hiding this comment

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

The type checking in the __truediv__ method should allow numeric types as well. Consider checking if other is an instance of Distance or a numeric type.

if not isinstance(other, Distance):
raise TypeError("Can only divide Distance or numeric types.")

self.km /= other

Choose a reason for hiding this comment

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

The __truediv__ method assumes other is numeric without proper type checking. Ensure other is either a Distance instance or a numeric type before performing the operation.

raise TypeError("Can only divide Distance or numeric types.")

self.km /= other
round(self.km, 2)

Choose a reason for hiding this comment

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

The round function is not modifying self.km as intended. Assign the result of round(self.km, 2) back to self.km to ensure the value is correctly rounded.

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