From eef4f43082f95c4302ad1531593c123efc08b38a Mon Sep 17 00:00:00 2001 From: Nikita Ponomarov Date: Sun, 1 Sep 2024 13:09:12 +0300 Subject: [PATCH 1/5] Solution --- app/main.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 52a3e644..7501276b 100644 --- a/app/main.py +++ b/app/main.py @@ -2,4 +2,72 @@ class Cargo: def __init__(self, weight: int) -> None: self.weight = weight -# write your code here + +class BaseRobot(Cargo): + def __init__(self, + name: str, + weight: int, + coords: list = None + ) -> None: + super().__init__(weight) + self.name = name + if coords is None: + self.coords = [0, 0] + else: + self.coords = coords + + def go_forward(self, step: int = 1) -> None: + self.coords[1] += step + + def go_back(self, step: int = 1) -> None: + self.coords[1] -= step + + def go_right(self, step: int = 1) -> None: + self.coords[0] += step + + def go_left(self, step: int = 1) -> None: + self.coords[0] -= step + + def get_info(self) -> str: + return f"Robot: {self.name}, Weight: {self.weight}" + + +class FlyingRobot(BaseRobot): + def __init__( + self, + name: str, + weight: int, + coords: list = None + ) -> None: + super().__init__(name, weight, coords) + if coords is None: + self.coords = [0, 0, 0] + else: + self.coords = coords + + def go_up(self, step: int = 1) -> None: + self.coords[2] += step + + def go_down(self, step: int = 1) -> None: + self.coords[2] -= step + + +class DeliveryDrone(FlyingRobot): + def __init__( + self, + name: str, + weight: int, + coords: list = None, + max_load_weight: int = 0, + current_load: int = None + ) -> None: + super().__init__(name, weight, coords) + self.max_load_weight = max_load_weight + self.current_load = current_load + + def hook_load(self, cargo: Cargo) -> None: + if self.current_load is None and cargo.weight <= self.max_load_weight: + self.current_load = cargo + + def unhook_load(self) -> None: + self.current_load = None From 80b33e1313345a7fa40f60ef981d9a817d098176 Mon Sep 17 00:00:00 2001 From: Nikita Ponomarov Date: Sun, 1 Sep 2024 18:58:00 +0300 Subject: [PATCH 2/5] Simplified coordinate assignment --- app/main.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/app/main.py b/app/main.py index 7501276b..a4a0a7de 100644 --- a/app/main.py +++ b/app/main.py @@ -11,10 +11,7 @@ def __init__(self, ) -> None: super().__init__(weight) self.name = name - if coords is None: - self.coords = [0, 0] - else: - self.coords = coords + self.coords = coords or [0, 0] def go_forward(self, step: int = 1) -> None: self.coords[1] += step @@ -39,11 +36,7 @@ def __init__( weight: int, coords: list = None ) -> None: - super().__init__(name, weight, coords) - if coords is None: - self.coords = [0, 0, 0] - else: - self.coords = coords + super().__init__(name, weight, coords or [0, 0, 0]) def go_up(self, step: int = 1) -> None: self.coords[2] += step From f625dcc0dc54cb4c9f2707de739fb28278fc316d Mon Sep 17 00:00:00 2001 From: Nikita Ponomarov Date: Sun, 1 Sep 2024 19:22:38 +0300 Subject: [PATCH 3/5] Correct annotation for current_load --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index a4a0a7de..f0269df3 100644 --- a/app/main.py +++ b/app/main.py @@ -58,7 +58,7 @@ def __init__( self.max_load_weight = max_load_weight self.current_load = current_load - def hook_load(self, cargo: Cargo) -> None: + def hook_load(self, cargo: Cargo | None) -> None: if self.current_load is None and cargo.weight <= self.max_load_weight: self.current_load = cargo From 43cb183d521d6617a2fbceb143e9a694478b3c2a Mon Sep 17 00:00:00 2001 From: Nikita Ponomarov Date: Mon, 2 Sep 2024 20:28:29 +0300 Subject: [PATCH 4/5] Correct annotation for current_load 2.0 --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index f0269df3..73f21d46 100644 --- a/app/main.py +++ b/app/main.py @@ -52,7 +52,7 @@ def __init__( weight: int, coords: list = None, max_load_weight: int = 0, - current_load: int = None + current_load: Cargo | None = None ) -> None: super().__init__(name, weight, coords) self.max_load_weight = max_load_weight From e661cde967249a086100561439f7e70dd7a8172d Mon Sep 17 00:00:00 2001 From: Nikita Ponomarov Date: Mon, 2 Sep 2024 21:07:38 +0300 Subject: [PATCH 5/5] placed each argument including self on a new line --- app/main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 73f21d46..eca6527e 100644 --- a/app/main.py +++ b/app/main.py @@ -4,11 +4,12 @@ def __init__(self, weight: int) -> None: class BaseRobot(Cargo): - def __init__(self, - name: str, - weight: int, - coords: list = None - ) -> None: + def __init__( + self, + name: str, + weight: int, + coords: list = None + ) -> None: super().__init__(weight) self.name = name self.coords = coords or [0, 0]