From 186cd60df9b992346cc4b24f972d86c98ab8299e Mon Sep 17 00:00:00 2001 From: eLQeR <131271125+eLQeR@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:22:16 +0300 Subject: [PATCH] Solution --- app/main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7defa3411..4a4fab18f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,51 @@ class Distance: - # Write your code here - pass + def __init__(self, km: int): + self.km = km + + def __repr__(self): + return f"Distance(km={self.km})" + def __str__(self): + return f"Distance: {self.km} kilometers." + + def __add__(self, other): + if isinstance(other, Distance): + return Distance(self.km + other.km) + return Distance(self.km + other) + + def __iadd__(self, other): + if isinstance(other, Distance): + self.km = self.km + other.km + return self + self.km = self.km + other + return self + def __mul__(self, other): + return Distance(self.km * other) + + def __truediv__(self, other): + return Distance(round(self.km / other, 2)) + + def __lt__(self, other): + if isinstance(other, Distance): + return self.km < other.km + return self.km < other + + def __gt__(self, other): + if isinstance(other, Distance): + return self.km > other.km + return self.km > other + + def __eq__(self, other): + if isinstance(other, Distance): + return self.km == other.km + return self.km == other + + def __le__(self, other): + if isinstance(other, Distance): + return self.km <= other.km + return self.km <= other + + def __ge__(self, other): + if isinstance(other, Distance): + return self.km >= other.km + return self.km >= other +