Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Solution #423

wants to merge 5 commits into from

Conversation

jinjo0222988
Copy link

No description provided.

@Abnormaltype Abnormaltype reopened this Mar 1, 2023
app/main.py Outdated
class Distance:
# Write your code here
pass
def __init__(self, km: any) -> None:
Copy link
Contributor

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

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:
Copy link
Contributor

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
Comment on lines 22 to 66
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
Copy link
Contributor

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

Copy link
Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove redundant else

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix everywhere

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __ge__(self, other: any) -> bool:
def __ge__(self, other: Distance | int | float) -> bool:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix everywhere

@jinjo0222988 jinjo0222988 requested a review from vsmutok October 18, 2023 21:41
app/main.py Outdated
class Distance:
# Write your code here
pass
def __init__(self, km: any) -> None:

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

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):

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

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)

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:

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
Comment on lines 22 to 26
if isinstance(other, Distance):
self.km += other.km
return self
self.km += other
return self

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make 1 return

Copy link

@Yurnerroo Yurnerroo left a 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
Comment on lines 16 to 19
km = self.km + other.km
return Distance(km)
km = self.km + other
return Distance(km)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants