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 #1694

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ ignore = E203, E266, W503, ANN002, ANN003, ANN101, ANN102, ANN401, N807, N818
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9,ANN,Q0,N8,VNE
exclude = venv, tests
exclude = .venv, tests
46 changes: 44 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
from __future__ import annotations


class Distance:
# Write your code here
pass
def __init__(self, km: float) -> None:
self.km = km

def __str__(self) -> str:
return f"Distance: {self.km} kilometers."

def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __add__(self, other: Distance | float) -> Distance:
if isinstance(other, Distance):
return Distance(self.km + other.km)
return Distance(self.km + other)

def __iadd__(self, other: Distance | float) -> Distance:
if isinstance(other, Distance):
self.km += other.km
return self
self.km += other
return self

def __mul__(self, other: Distance | float) -> Distance:
return Distance(self.km * other)
Comment on lines +26 to +27

Choose a reason for hiding this comment

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

The __mul__ method should handle both Distance objects and numeric types. Currently, it only supports numeric types. You need to add logic to handle the case where other is a Distance object.


def __truediv__(self, other: Distance | float) -> Distance:
return Distance(round(self.km / other, 2))
Comment on lines +29 to +30

Choose a reason for hiding this comment

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

The __truediv__ method should handle both Distance objects and numeric types. Currently, it only supports numeric types. You need to add logic to handle the case where other is a Distance object.


def __lt__(self, other: Distance | float) -> bool:
return self.km < other
Comment on lines +32 to +33

Choose a reason for hiding this comment

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

The __lt__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.


def __gt__(self, other: Distance | float) -> bool:
return self.km > other
Comment on lines +35 to +36

Choose a reason for hiding this comment

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

The __gt__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.


def __eq__(self, other: Distance | float) -> bool:
return self.km == other
Comment on lines +38 to +39

Choose a reason for hiding this comment

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

The __eq__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.


def __le__(self, other: Distance | float) -> bool:
return self.km <= other
Comment on lines +41 to +42

Choose a reason for hiding this comment

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

The __le__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.


def __ge__(self, other: Distance | float) -> bool:
return self.km >= other
Comment on lines +44 to +45

Choose a reason for hiding this comment

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

The __ge__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

Loading