-
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' #820
base: master
Are you sure you want to change the base?
'solution' #820
Conversation
app/main.py
Outdated
def __repr__(self) -> str: | ||
return f"Distance(km={self.km})" | ||
|
||
def __lt__(self, other: int) -> 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.
other
can be float and Distance too. Please, rewrite your functions.
app/main.py
Outdated
return f"Distance(km={self.km})" | ||
|
||
def __lt__(self, other: int | float | Distance) -> bool: | ||
return True if self.km < other else False |
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.
In this case you can do
return True if self.km < other else False | |
return self.km < other |
Fix in all places
app/main.py
Outdated
def __iadd__(self, other: int | float | Distance) -> Distance: | ||
if isinstance(other, (int, float)): | ||
self.km += other | ||
return self |
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.
Move return after if-else statement
app/main.py
Outdated
def __mul__(self, other: int | float | Distance) -> Distance: | ||
return Distance(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.
You need to check if the other is a distance, or an int, or a float. If it's an instance of distance, then you'll have to operate with other, not just other. Do it in other function too.
def __mul__(self, other: int | float | Distance) -> Distance: | |
return Distance(self.km * other) | |
def __mul__(self, other: int | float | Distance) -> Distance: | |
if isinstance(other, Distance): | |
return Distance(self.km * other.km) | |
return Distance(self.km * other) |
app/main.py
Outdated
def __truediv__(self, other: int | float | Distance) -> Distance: | ||
return Distance(round(self.km / other, 2)) | ||
|
||
def __mul__(self, other: int | float | Distance) -> 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.
other
can't be Distance in this function
app/main.py
Outdated
def __truediv__(self, other: int | float | Distance) -> Distance: | ||
return Distance(round(self.km / other, 2)) | ||
|
||
def __mul__(self, other: int | float | Distance) -> 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.
def __mul__(self, other: int | float | Distance) -> Distance: | |
def __mul__(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.
Good job!
No description provided.