Не изменяя существующий класс и команды лифта, добавьте безопасное перемещение: перед движением нужно убедиться, что двери закрыты.
Asked at
AI answer
Add a check immediately before movement begins, and do not call the movement command if the doors are not closed. The existing class and commands can remain unchanged; the specific method names depend on the code provided. For example:
def move_safely(elevator, destination):
if not elevator.doors_are_closed():
raise RuntimeError("Cannot move: elevator doors are open")
elevator.move_to(destination)
If commands are represented as strings or command objects, the same check should be placed in the shared execution path for the movement command. The check must run immediately before movement so the door state does not become stale between the check and the start of movement.
Also asked at Касперский
Similar questions
- Review the code for bugs, security vulnerabilities, and other issues, and explain them from top to bottom. Then suggest how to fix them.
- What metrics can be determined using the len() function in Python?
- How can you explicitly trigger an exception in negative testing?
- Why is the socket module needed?
- What is the role of methods in software development and why are they used?