Please note: read the guideline before starting.
Let's implement 3 classes with inheritance
BaseRobot
-
the
__init__method takesname,weight,coords, and saves them -
coordsis list withxandycoordinates, set to [0, 0] by default. -
go_forward,go_back,go_rightandgo_leftmethods take astepargument (1 by default) and move the robot bystepin the appropriate direction. Positive Y axis is forward, positive X axis is right. These functions should not return anything. -
get_infomethod returns a string in the next formatRobot: {name}, Weight: {weight}
robot = BaseRobot(name="Walle", weight=34, coords=[3, -2])
robot.go_forward()
# robot.coords == [3, -1]
robot.go_right(5)
# robot.coords == [8, -1]FlyingRobot
- inherits from
BaseRobot - takes the same args as BaseRobot and passes them to the
parent's
__init__method (use super) - can work with z coordinate, coords by default should be [0, 0, 0],
use condition to send right coords to parent's
__init__method - has methods
go_upandgo_downchangingz, positive Z axis is up
flying_robot = FlyingRobot(name="Mike", weight=11)
flying_robot.go_up(10)
# flying_robot.coords = [0, 0, 10]DeliveryDrone
- inherits from
FlyingRobot - takes the same args as
FlyingRobotand passes them to the parent's__init__method. - the
__init__method also takes and storesmax_load_weightandcurrent_load.max_load_weightpurpose is to store the robot's load capacity;current_loadpurpose is to store theCargoinstance, which can be None by default. IfCargoobject was passed to function, use methodhook_loadto check if it can be hooked.
- has
hook_loadmethod takingCargoobject and saves it tocurrent_loadif two conditions are True:current_loadis set toNoneandcargo.weightis not greater thanmax_load_weightof the drone. Otherwise, do nothing. - has
unhook_loadmethod, that setscurrent_loadto None without any additional logic.
cargo = Cargo(14)
drone = DeliveryDrone(
name="Jim",
weight=18,
coords=[11, -4, 16],
max_load_weight=20,
current_load=None,
)
drone.hook_load(cargo)
# drone.current_load is cargo
cargo2 = Cargo(2)
drone.hook_load(cargo2)
# drone.current_load is cargo
# didn't hook cargo2, cargo already in current loaddrone = DeliveryDrone(
name="Jack",
weight=9,
max_load_weight=30,
current_load=Cargo(20),
)
drone.unhook_load()
# drone.current_load is None