Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution_ver-1 #1266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,61 @@ 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 if coords is not None else [0, 0]

def go_forward(self, steps: int = 1) -> list[int]:
self.coords[1] += steps
return self.coords

def go_back(self, steps: int = 1) -> list[int]:
self.coords[1] -= steps
return self.coords

def go_right(self, steps: int = 1) -> list[int]:
self.coords[0] += steps
return self.coords

def go_left(self, steps: int = 1) -> list[int]:
self.coords[0] -= steps
return self.coords

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, weight, coords)
self.coords = coords if coords is not None else [0, 0, 0]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the FlyingRobot class, the initialization of self.coords should not be repeated after calling the super().init() method. The super class BaseRobot already initializes self.coords, so this line is unnecessary and could lead to confusion or errors.


def go_up(self, steps: int = 1) -> list[int]:
self.coords[2] += steps
return self.coords

def go_down(self, steps: int = 1) -> list[int]:
self.coords[2] -= steps
return self.coords


class DeliveryDrone(FlyingRobot):
def __init__(self, name: str, weight: int,
max_load_weight: int,
coords: list[int] = None,
current_load: Cargo = None) -> None:
super().__init__(name, weight, coords)
self.max_load_weight = max_load_weight
self.current_load = current_load

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the DeliveryDrone class, when initializing self.current_load, it might be a good idea to check if the current_load's weight does not exceed max_load_weight. This would ensure that the drone does not start with an overloaded cargo.


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
Loading