Introduction
Starting and stopping a drone safely is critical to avoid accidents or damage. The arming and disarming sequence controls when the drone's motors can spin, ensuring it only flies when intended and stops promptly when done.
Imagine starting a car: you must insert the key and turn it to start the engine, and when you park, you turn the key back to stop the engine. This process ensures the car only runs when you want it to and stops safely.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ Safety │──────▶│ Arming │──────▶│ Motors │
│ Checks │ │ Sequence │ │ Start │
└───────────────┘ └───────────────┘ └───────────────┘
│
▼
┌───────────────┐
│ Flight │
│ Operation │
└───────────────┘
│
▼
┌───────────────┐ ┌───────────────┐
│ Disarming │──────▶│ Motors │
│ Sequence │ │ Stop │
└───────────────┘ └───────────────┘arming a drone do in the flight sequence?drone_state = {'armed': False}
def arm():
if not drone_state['armed']:
drone_state['armed'] = True
return 'Drone armed'
else:
return 'Drone already armed'
print(arm())
print(arm())drone_state = {'armed': True}
def disarm():
if drone_state['armed'] = True:
drone_state['armed'] = False
return 'Drone disarmed'
else:
return 'Drone already disarmed'
print(disarm())toggle_arm() that arms the drone if disarmed, and disarms if armed. Given drone_state = {'armed': False}, which code correctly implements this behavior?Pass the test and this pattern moves unknown