From ab24b9ffe9b8d1ca6314034393d66753e8ed92da Mon Sep 17 00:00:00 2001 From: Yehor Date: Sun, 22 Dec 2024 17:43:31 +0200 Subject: [PATCH] Solution --- app/main.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7defa3411..29024e867 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,66 @@ 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): + return Distance( + km=self.km + other.km + ) + + def __iadd__(self, other): + if isinstance(other, Distance): + self.km += other.km + return self + elif isinstance(other, int): + self.km += other + return self + + def __mul__(self, other): + if isinstance(other, Distance): + self.km *= other.km + return self + elif isinstance(other, int): + self.km *= other + return self + + def __truediv__(self, other): + if isinstance(other, Distance): + self.km = round(self.km / other.km, 2) + return self, 2 + elif isinstance(other, int): + self.km = round(self.km / other, 2) + return self + + def __lt__(self, other): + if isinstance(other, Distance): + return self.km < other.km + elif isinstance(other, int): + return self.km < other + + def __gt__(self, other): + if isinstance(other, Distance): + return self.km > other.km + elif isinstance(other, int): + return self.km > other + + def __eq__(self, other): + if isinstance(other, Distance): + return self.km == other.km + elif isinstance(other, int): + return self.km == other + + def __le__(self, other): + if isinstance(other, Distance): + return self.km != other.km + elif isinstance(other, int): + return self.km != other + + def __ge__(self, other): + if isinstance(other, Distance): + return self.km >= other.km + elif isinstance(other, int): + return self.km >= other