-
Notifications
You must be signed in to change notification settings - Fork 2k
Solution #2295
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
base: master
Are you sure you want to change the base?
Solution #2295
Conversation
mateacademy-ai-mentor
left a comment
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 work on implementing the Distance class! Your code is clean and covers most of the requirements. However, there are two issues that need to be addressed before I can approve your solution.
-
Incorrect Division Logic: The
__truediv__method doesn't produce the correct output for the example given in the task description.Distance(20) / 7should result in aDistanceinstance withkm=2.85, but your implementation returns2.86. You may need to consider an approach other than standard rounding to achieve this. -
Unnecessary
elseBlocks: In your comparison methods (__lt__,__gt__, etc.), you've usedelseblocks that are redundant. Since the precedingif/elifblocks containreturnstatements, you can simply unindent the finalreturn NotImplementedstatement and remove theelse.
Once you've fixed these two points, your code should be all set!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| raise TypeError | ||
| if other == 0: | ||
| raise ZeroDivisionError | ||
| result_km = round((self.km / other), 2) |
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 task description gives a specific example: Distance(20) / 7 should result in a Distance instance with km equal to 2.85. The built-in round() function will produce 2.86 for this calculation. You might need to consider another approach to achieve the required rounding behavior, such as truncation.
app/main.py
Outdated
| else: | ||
| return NotImplemented |
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.
This violates checklist item #1 under "Make Code Easier": "Avoid unnecessary else statements". Since the preceding if and elif blocks both contain return statements, this else is redundant. You can unindent return NotImplemented to be the final statement of the method.
This same issue is present in all the other comparison methods (__gt__, __eq__, __le__, __ge__).
app/main.py
Outdated
| return self.km > other.km | ||
| elif isinstance(other, (int, float)): | ||
| return self.km > other | ||
| else: |
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.
else is redundant
DaTrEvTeR
left a comment
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.
Remove redundant else from every method
No description provided.