Motion¶
Write the function motion to be executed by the miniprocessor
controlling a lift. Once the lift is at a certain floor, the function
applies a set of rules and returns an integer stating if the
lift must go upwards (1), downwards (-1) or stay still(0).
The function takes one integer parameter and two boolean parameters.
The integer says if there is an upwards(1), downwards (-1) or
no (0) request from inside the lift. The first boolean parameter
says if there is a request for the lift from somewhere up (True)
or not(False).The second boolean parameter
says the same somewhere down the actual position of the lift.
The ruke to be applied states that the lift follows first the
order from inside, and, if there is no request from the inside,
it follows requests from the outside, giving the priority to
requests to go up, if there are requests from both directions.
Save the function in a file motion.py.
The function must pass the following doctest:
>>> motion(0, True, True) 1 >>> motion(-1, True, False) -1Note
You can download the file with tests
motion.txt