-
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 #423
base: master
Are you sure you want to change the base?
Solution #423
Conversation
app/main.py
Outdated
class Distance: | ||
# Write your code here | ||
pass | ||
def __init__(self, km: any) -> 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.
put the correct type annotation
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.
not fixed it can be float | int
app/main.py
Outdated
def __repr__(self) -> str: | ||
return f"Distance(km={self.km})" | ||
|
||
def __add__(self, other: any) -> 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.
put the correct type annotation
app/main.py
Outdated
def __iadd__(self, other: any) -> Distance: | ||
if isinstance(other, Distance): | ||
self.km += other.km | ||
return self | ||
else: | ||
self.km += other | ||
return self | ||
|
||
def __mul__(self, other: any) -> Distance: | ||
self.km = self.km * other | ||
return self | ||
|
||
def __truediv__(self, other: any) -> Distance: | ||
self.km = round(self.km / other, 2) | ||
return self | ||
|
||
def __lt__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km < other.km | ||
else: | ||
return self.km < other | ||
|
||
def __gt__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km > other.km | ||
else: | ||
return self.km > other | ||
|
||
def __eq__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km == other.km | ||
else: | ||
return self.km == other | ||
|
||
def __le__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km <= other.km | ||
else: | ||
return self.km <= other | ||
|
||
def __ge__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km >= other.km | ||
else: | ||
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.
put the correct type annotation
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.
I don't understand why annotations type is wrong?
app/main.py
Outdated
def __ge__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km >= other.km | ||
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.
remove redundant 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.
fix everywhere
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.
not fixed
app/main.py
Outdated
else: | ||
return self.km <= other | ||
|
||
def __ge__(self, other: any) -> 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.
def __ge__(self, other: any) -> bool: | |
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.
fix everywhere
app/main.py
Outdated
class Distance: | ||
# Write your code here | ||
pass | ||
def __init__(self, km: any) -> 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.
not fixed it can be float | int
app/main.py
Outdated
return self | ||
else: | ||
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
return f"Distance(km={self.km})" | ||
|
||
def __add__(self, other: Distance | int | float) -> Distance: | ||
if isinstance(other, 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.
add must create new instance instead of change current
app/main.py
Outdated
return self | ||
|
||
def __mul__(self, other: Distance | int | float) -> Distance: | ||
self.km = 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.
mul must create new instance instead of change current
app/main.py
Outdated
return self | ||
|
||
def __truediv__(self, other: Distance | int | float) -> Distance: | ||
self.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.
truediv must create new instance instead of change current
app/main.py
Outdated
def __ge__(self, other: any) -> bool: | ||
if isinstance(other, Distance): | ||
return self.km >= other.km | ||
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.
not fixed
app/main.py
Outdated
if isinstance(other, Distance): | ||
self.km += other.km | ||
return self | ||
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.
make 1 return
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.
checks didn't pass
app/main.py
Outdated
km = self.km + other.km | ||
return Distance(km) | ||
km = self.km + other | ||
return Distance(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.
make 1 return here as well
No description provided.