-
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 #1672
base: master
Are you sure you want to change the base?
Solution #1672
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.
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:
-
Comparison Methods: The comparison methods (
__lt__
,__gt__
,__eq__
,__le__
,__ge__
) currently have incorrect logic when comparingDistance
objects. Make sure to compare thekm
attributes of theDistance
objects (e.g.,self.km < other.km
) rather than comparing the object itself. -
Return Types: The return types for the comparison methods should be
bool
, notfloat
. These methods should return a boolean value indicating the result of the comparison. -
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: |
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.
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
if isinstance(other, Distance): | ||
return self.km < other |
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.
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: |
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.
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
if isinstance(other, Distance): | ||
return self.km > other |
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.
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: |
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.
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
if isinstance(other, Distance): | ||
return self.km == other |
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.
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: |
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.
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
if isinstance(other, Distance): | ||
return self.km <= other |
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.
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: |
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.
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
if isinstance(other, Distance): | ||
return self.km >= other |
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.
When comparing with another Distance
object, you should compare self.km >= other.km
instead of self.km >= other
.
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.
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:
-
Constructor Type Annotation: The
__init__
method should have the parameterkm
annotated asfloat
orint
instead ofbool
. This will ensure that the class handles distance values appropriately. -
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. -
Comparison Methods Type Annotations: The parameter
other
in the comparison methods (__lt__
,__gt__
,__eq__
,__le__
,__ge__
) should be annotated asDistance
,int
, orfloat
, notbool
. 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: |
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.
The constructor parameter km
should be of type float
or int
, not bool
. This is likely a mistake in the type annotation.
def __truediv__(self, other: Distance) -> Distance: | ||
if isinstance(other, (int, float)): | ||
result_km = round(self.km / other, 2) | ||
return Distance(result_km) |
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.
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: |
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.
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: |
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.
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: |
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.
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: |
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.
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: |
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.
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.
No description provided.