From 0dc521010829876cf5ee2575a1cf054648567efa Mon Sep 17 00:00:00 2001 From: Daryna Kiiashko Date: Wed, 15 Jul 2026 11:56:38 +0300 Subject: [PATCH 1/2] Solution --- app/main.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7defa3411..c3a182919 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,56 @@ +from __future__ import annotations + + class Distance: - # Write your code here - pass + + def __init__(self, km: int | 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) -> Distance: + if isinstance(other, Distance): + return Distance(self.km + other.km) + return Distance(self.km + other) + + def __iadd__(self, other: Distance) -> Distance: + if isinstance(other, Distance): + self.km += other.km + else: + self.km += other + return self + + def __mul__(self, other: Distance) -> Distance: + return Distance(self.km * other) + + def __truediv__(self, other: Distance) -> Distance: + return Distance(round(self.km / other, 2)) + + def __lt__(self, other: Distance) -> bool: + if isinstance(other, Distance): + return self.km < other.km + return self.km < other + + def __gt__(self, other: Distance) -> bool: + if isinstance(other, Distance): + return self.km > other.km + return self.km > other + + def __eq__(self, other: Distance) -> bool: + if isinstance(other, Distance): + return self.km == other.km + return self.km == other + + def __le__(self, other: Distance) -> bool: + if isinstance(other, Distance): + return self.km <= other.km + return self.km <= other + + def __ge__(self, other: Distance) -> bool: + if isinstance(other, Distance): + return self.km >= other.km + return self.km >= other From aceaaf2e001100e19ce289cc6eb3c906e7f9f4b7 Mon Sep 17 00:00:00 2001 From: Daryna Kiiashko Date: Wed, 15 Jul 2026 12:22:19 +0300 Subject: [PATCH 2/2] Solution --- app/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/main.py b/app/main.py index c3a182919..e80d17eac 100644 --- a/app/main.py +++ b/app/main.py @@ -12,22 +12,22 @@ def __str__(self) -> str: def __repr__(self) -> str: return f"Distance(km={self.km})" - def __add__(self, other: Distance) -> Distance: + def __add__(self, other: int | float | Distance) -> Distance: if isinstance(other, Distance): return Distance(self.km + other.km) return Distance(self.km + other) - def __iadd__(self, other: Distance) -> Distance: + def __iadd__(self, other: int | float | Distance) -> Distance: if isinstance(other, Distance): self.km += other.km - else: - self.km += other + return self + self.km += other return self - def __mul__(self, other: Distance) -> Distance: + def __mul__(self, other: int | float) -> Distance: return Distance(self.km * other) - def __truediv__(self, other: Distance) -> Distance: + def __truediv__(self, other: int | float) -> Distance: return Distance(round(self.km / other, 2)) def __lt__(self, other: Distance) -> bool: