From b615fd54edb4db59cc646ba4a6d727a96b462d41 Mon Sep 17 00:00:00 2001 From: Aleksandra Prognimak Date: Wed, 25 Oct 2023 20:18:28 +0300 Subject: [PATCH 1/3] 'Solution' --- app/main.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7defa3411..b17dc9307 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,45 @@ +from __future__ import annotations + + class Distance: - # Write your code here - pass + def __init__(self, km: int | float) -> None: + self.km = km + + @staticmethod + def get_km(other: Distance | int | float) -> int | float: + return other.km if isinstance(other, Distance) else other + + 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 | int | float) -> Distance: + return Distance(km=self.km + self.get_km(other)) + + def __iadd__(self, other: Distance | int | float) -> Distance: + self.km += self.get_km(other) + + return self + + def __mul__(self, num: int) -> Distance: + return Distance(km=self.km * num) + + def __truediv__(self, num: int) -> Distance: + return Distance(km=round(self.km / num, 2)) + + def __lt__(self, other: Distance | int | float) -> bool: + return self.km < self.get_km(other) + + def __gt__(self, other: Distance | int | float) -> bool: + return self.km > self.get_km(other) + + def __eq__(self, other: Distance | int | float) -> bool: + return self.km == self.get_km(other) + + def __le__(self, other: Distance | int | float) -> bool: + return self.km <= self.get_km(other) + + def __ge__(self, other: Distance | int | float) -> bool: + return self.km >= self.get_km(other) From 985316e5c701c1042d417346cbd5cb701db7b2b7 Mon Sep 17 00:00:00 2001 From: Aleksandra Prognimak Date: Sat, 28 Oct 2023 00:28:58 +0300 Subject: [PATCH 2/3] fixed --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index b17dc9307..0f27536d6 100644 --- a/app/main.py +++ b/app/main.py @@ -39,7 +39,7 @@ def __eq__(self, other: Distance | int | float) -> bool: return self.km == self.get_km(other) def __le__(self, other: Distance | int | float) -> bool: - return self.km <= self.get_km(other) + return not self.__gt__(other) def __ge__(self, other: Distance | int | float) -> bool: - return self.km >= self.get_km(other) + return not self.__lt__(other) From 465e0ef67c80db9eaafbd60efce6b29ddb0f7445 Mon Sep 17 00:00:00 2001 From: Aleksandra Prognimak Date: Tue, 31 Oct 2023 13:11:35 +0200 Subject: [PATCH 3/3] fixed --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 0f27536d6..411adb35c 100644 --- a/app/main.py +++ b/app/main.py @@ -39,7 +39,7 @@ def __eq__(self, other: Distance | int | float) -> bool: return self.km == self.get_km(other) def __le__(self, other: Distance | int | float) -> bool: - return not self.__gt__(other) + return not self.km > other def __ge__(self, other: Distance | int | float) -> bool: - return not self.__lt__(other) + return not self.km < other