-
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 #1670
base: master
Are you sure you want to change the base?
Solution #1670
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.
Your implementation of the Distance
class is well-structured and meets the task requirements. 🎉 The only minor issue is with the type annotations, where quotes are used unnecessarily. Consider using from __future__ import annotations
to handle forward references without quotes. Keep up the great work and happy coding! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
@@ -1,3 +1,52 @@ | |||
class Distance: | |||
# Write your code here | |||
pass | |||
def __init__(self, km: "int | float") -> 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 type hint km: "int | float"
should not be enclosed in quotes. It should be km: int | float
.
def __repr__(self) -> str: | ||
return f"Distance(km={self.km})" | ||
|
||
def __add__(self, other: '"Distance" | int | float') -> "Distance": |
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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
return Distance(self.km + other) | ||
return Distance(self.km + other.km) | ||
|
||
def __iadd__(self, other: '"Distance" | int | float') -> "Distance": |
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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
def __mul__(self, other: int) -> "Distance": | ||
return Distance(self.km * other) | ||
|
||
def __truediv__(self, other: "int | float") -> "Distance": |
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 type hint other: "int | float"
should not be enclosed in quotes. It should be other: int | float
.
def __truediv__(self, other: "int | float") -> "Distance": | ||
return Distance(round(self.km / other, 2)) | ||
|
||
def __lt__(self, other: '"Distance" | int | float') -> 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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
return self.km < other | ||
return self.km < other.km | ||
|
||
def __gt__(self, other: '"Distance" | int | float') -> 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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
return self.km > other | ||
return self.km > other.km | ||
|
||
def __eq__(self, other: '"Distance" | int | float') -> 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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
return self.km == other | ||
return self.km == other.km | ||
|
||
def __le__(self, other: '"Distance" | int | float') -> 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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
return self.km <= other | ||
return self.km <= other.km | ||
|
||
def __ge__(self, other: '"Distance" | int | float') -> 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 type hint other: '"Distance" | int | float'
should not be enclosed in quotes. It should be other: Distance | int | float
.
No description provided.