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' #820

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

'solution' #820

wants to merge 5 commits into from

Conversation

xborismenx
Copy link

No description provided.

app/main.py Outdated
def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __lt__(self, other: int) -> bool:

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

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

Suggested change
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

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
Comment on lines 46 to 47
def __mul__(self, other: int | float | Distance) -> Distance:
return Distance(self.km * other)

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.

Suggested change
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)

@xborismenx xborismenx requested a review from NikOneZ1 October 27, 2023 21:15
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:

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:

Choose a reason for hiding this comment

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

Suggested change
def __mul__(self, other: int | float | Distance) -> Distance:
def __mul__(self, other: int | float) -> Distance:

Copy link

@NikOneZ1 NikOneZ1 left a comment

Choose a reason for hiding this comment

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

Good job!

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.

4 participants