From 4beeb269b3cc6b655378b9db76984e10833500c2 Mon Sep 17 00:00:00 2001 From: DMYTRO YURCHYSHYN Date: Mon, 7 Oct 2024 21:43:55 +0300 Subject: [PATCH] Solution --- app/main.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 52a3e644..c50643c8 100644 --- a/app/main.py +++ b/app/main.py @@ -2,4 +2,67 @@ class Cargo: def __init__(self, weight: int) -> None: self.weight = weight -# write your code here + +class BaseRobot: + def __init__( + self, + name: str, + weight: int, + coords: list[int] = None + ) -> None: + self.name = name + self.weight = weight + self.coords = coords or [0, 0] + + 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[int] = None + ) -> None: + super().__init__(name=name, weight=weight, coords=coords) + self.coords = coords or [0, 0, 0] + + 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, + max_load_weight: int, + current_load: Cargo, + coords: list[int] = None + ) -> None: + super().__init__(name=name, weight=weight, coords=coords) + self.current_load = current_load + self.max_load_weight = max_load_weight + + 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