From 998712338fcb46bb58752465866bdc1ace0faf12 Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 13:41:22 +0200 Subject: [PATCH 1/6] Solve --- app/main.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 7defa3411..bcc65ada1 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,74 @@ +from typing import Any + + class Distance: - # Write your code here - pass + def __init__(self, km: int | float): + self.km = km + + def __str__(self): + return f"Distance: {self.km} kilometers." + + def __repr__(self): + return f"Distance(km={self.km})" + + def __add__(self, other: Any): + if isinstance(other, Distance): + return Distance(self.km + other.km) + elif isinstance(other, int | float): + return Distance(self.km + other) + else: + return None + + def __iadd__(self, other: Any): + if isinstance(other, Distance): + self.km += other.km + elif isinstance(other, int | float): + self.km += other + return self + + def __mul__(self, other: Any): + if isinstance(other, int | float): + return Distance(self.km * other) + else: + return None + + def __truediv__(self, other: Any): + if isinstance(other, int | float): + return Distance(round(self.km / other, 2)) + else: + return None + + def __lt__(self, other: Any): + if isinstance(other, Distance): + return self.km < other.km + elif isinstance(other, int | float): + return self.km < other + return None + + def __le__(self, other: Any): + if isinstance(other, Distance): + return self.km <= other.km + elif isinstance(other, int | float): + return self.km <= other + return None + + def __gt__(self, other: Any): + if isinstance(other, Distance): + return self.km > other.km + elif isinstance(other, int | float): + return self.km > other + return None + + def __ge__(self, other: Any): + if isinstance(other, Distance): + return self.km >= other.km + elif isinstance(other, int | float): + return self.km >= other + return None + + def __eq__(self, other: Any): + if isinstance(other, Distance): + return self.km == other.km + elif isinstance(other, int | float): + return self.km == other + return None From 3c3be23e9a61a3bfd49289992e8a1ff2e358c79c Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 14:02:56 +0200 Subject: [PATCH 2/6] Fix flake8 --- app/main.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/app/main.py b/app/main.py index bcc65ada1..81a925073 100644 --- a/app/main.py +++ b/app/main.py @@ -1,17 +1,18 @@ +from __future__ import annotations from typing import Any class Distance: - def __init__(self, km: int | float): + def __init__(self, km: int | float) -> None: self.km = km - def __str__(self): + def __str__(self) -> str: return f"Distance: {self.km} kilometers." - def __repr__(self): + def __repr__(self) -> str: return f"Distance(km={self.km})" - def __add__(self, other: Any): + def __add__(self, other: Any) -> Distance | None: if isinstance(other, Distance): return Distance(self.km + other.km) elif isinstance(other, int | float): @@ -19,56 +20,56 @@ def __add__(self, other: Any): else: return None - def __iadd__(self, other: Any): + def __iadd__(self, other: Any) -> Distance: if isinstance(other, Distance): self.km += other.km elif isinstance(other, int | float): self.km += other return self - def __mul__(self, other: Any): + def __mul__(self, other: Any) -> Distance | None: if isinstance(other, int | float): return Distance(self.km * other) else: return None - def __truediv__(self, other: Any): + def __truediv__(self, other: Any) -> Distance | None: if isinstance(other, int | float): return Distance(round(self.km / other, 2)) else: return None - def __lt__(self, other: Any): + def __lt__(self, other: Any) -> bool: if isinstance(other, Distance): return self.km < other.km elif isinstance(other, int | float): return self.km < other - return None + return False - def __le__(self, other: Any): + def __le__(self, other: Any) -> bool: if isinstance(other, Distance): return self.km <= other.km elif isinstance(other, int | float): return self.km <= other - return None + return False - def __gt__(self, other: Any): + def __gt__(self, other: Any) -> bool: if isinstance(other, Distance): return self.km > other.km elif isinstance(other, int | float): return self.km > other - return None + return False - def __ge__(self, other: Any): + def __ge__(self, other: Any) -> bool: if isinstance(other, Distance): return self.km >= other.km elif isinstance(other, int | float): return self.km >= other - return None + return False - def __eq__(self, other: Any): + def __eq__(self, other: Any) -> bool: if isinstance(other, Distance): return self.km == other.km elif isinstance(other, int | float): return self.km == other - return None + return False From 4f13d88f71448ec226ea493b69eb6dbc6ecf9226 Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 14:18:22 +0200 Subject: [PATCH 3/6] Fix flake8 --- app/main.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/main.py b/app/main.py index 81a925073..79c830c82 100644 --- a/app/main.py +++ b/app/main.py @@ -12,62 +12,59 @@ def __str__(self) -> str: def __repr__(self) -> str: return f"Distance(km={self.km})" - def __add__(self, other: Any) -> Distance | None: + def __add__(self, other: Distance | int | float) -> Distance: if isinstance(other, Distance): return Distance(self.km + other.km) elif isinstance(other, int | float): return Distance(self.km + other) - else: - return None + raise TypeError - def __iadd__(self, other: Any) -> Distance: + def __iadd__(self, other: Distance | int | float) -> Distance: if isinstance(other, Distance): self.km += other.km elif isinstance(other, int | float): self.km += other return self - def __mul__(self, other: Any) -> Distance | None: + def __mul__(self, other: int | float) -> Distance: if isinstance(other, int | float): return Distance(self.km * other) - else: - return None + raise TypeError - def __truediv__(self, other: Any) -> Distance | None: + def __truediv__(self, other: int | float) -> Distance: if isinstance(other, int | float): return Distance(round(self.km / other, 2)) - else: - return None + raise TypeError - def __lt__(self, other: Any) -> bool: + def __lt__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km < other.km elif isinstance(other, int | float): return self.km < other return False - def __le__(self, other: Any) -> bool: + def __le__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km <= other.km elif isinstance(other, int | float): return self.km <= other return False - def __gt__(self, other: Any) -> bool: + def __gt__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km > other.km elif isinstance(other, int | float): return self.km > other return False - def __ge__(self, other: Any) -> bool: + def __ge__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km >= other.km elif isinstance(other, int | float): return self.km >= other return False - def __eq__(self, other: Any) -> bool: + def __eq__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km == other.km elif isinstance(other, int | float): From 429cfc43fd715df6c3056069d80852f12a40d0b2 Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 14:19:34 +0200 Subject: [PATCH 4/6] Fix flake8 --- app/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/app/main.py b/app/main.py index 79c830c82..6c42a003b 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,4 @@ from __future__ import annotations -from typing import Any class Distance: From 573bcde39099c068eeb7e0478a7d423db405fb4b Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 14:31:12 +0200 Subject: [PATCH 5/6] Fix flake8 --- app/main.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/main.py b/app/main.py index 6c42a003b..d2d989ba1 100644 --- a/app/main.py +++ b/app/main.py @@ -14,14 +14,14 @@ def __repr__(self) -> str: def __add__(self, other: Distance | int | float) -> Distance: if isinstance(other, Distance): return Distance(self.km + other.km) - elif isinstance(other, int | float): + if isinstance(other, int | float): return Distance(self.km + other) raise TypeError def __iadd__(self, other: Distance | int | float) -> Distance: if isinstance(other, Distance): self.km += other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): self.km += other return self @@ -38,34 +38,34 @@ def __truediv__(self, other: int | float) -> Distance: def __lt__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km < other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): return self.km < other return False def __le__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km <= other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): return self.km <= other return False def __gt__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km > other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): return self.km > other return False def __ge__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km >= other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): return self.km >= other return False def __eq__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km == other.km - elif isinstance(other, int | float): + if isinstance(other, int | float): return self.km == other return False From 78d738869cbfcc3c531c650ed8c164b15e6a6af5 Mon Sep 17 00:00:00 2001 From: krzyb5081 Date: Sat, 4 Jul 2026 14:50:18 +0200 Subject: [PATCH 6/6] Fix flake8 --- app/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index d2d989ba1..9a725045b 100644 --- a/app/main.py +++ b/app/main.py @@ -40,32 +40,32 @@ def __lt__(self, other: Distance | int | float) -> bool: return self.km < other.km if isinstance(other, int | float): return self.km < other - return False + return NotImplemented def __le__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km <= other.km if isinstance(other, int | float): return self.km <= other - return False + return NotImplemented def __gt__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km > other.km if isinstance(other, int | float): return self.km > other - return False + return NotImplemented def __ge__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km >= other.km if isinstance(other, int | float): return self.km >= other - return False + return NotImplemented def __eq__(self, other: Distance | int | float) -> bool: if isinstance(other, Distance): return self.km == other.km if isinstance(other, int | float): return self.km == other - return False + return NotImplemented