Consider this drone landing code snippet. What will be printed after execution?
drone_status = {'flying': True, 'armed': True}
if drone_status['flying']:
print('Landing initiated')
drone_status['flying'] = False
if not drone_status['flying'] and drone_status['armed']:
print('Disarming drone')
drone_status['armed'] = False
print(f"Flying: {drone_status['flying']}, Armed: {drone_status['armed']}")Check the order of status changes and conditions.
The drone starts flying and armed. The first if triggers landing and sets flying to False. Then the second if triggers disarming because flying is False and armed is True. Finally, both are False.
In drone programming, which condition best ensures the drone is safe to disarm?
Think about when the drone is fully landed.
Safe disarming requires the drone to be fully landed (altitude zero) and not flying. Battery level is not directly related to disarming safety.
Review this code snippet. Why does the drone never disarm?
drone = {'flying': True, 'armed': True, 'altitude': 5}
if drone['altitude'] == 0:
drone['flying'] = False
if not drone['flying']:
drone['armed'] = False
print(f"Armed: {drone['armed']}")Check the altitude value and conditions.
The altitude is 5, so the first if never sets flying to False. The second if depends on flying being False to disarm, so disarming never happens.
Which option correctly identifies the syntax error in this code?
if drone['flying'] == True drone['flying'] = False drone['armed'] = False
Look at the if statement syntax.
Python requires a colon ':' at the end of the if condition line. Without it, a SyntaxError occurs.
Given this code, how many times will the print statement execute during the landing and disarming process?
steps = ['descend', 'touchdown', 'stop_motors', 'disarm'] for step in steps: if step == 'descend': print('Descending...') elif step == 'touchdown': print('Touchdown confirmed') elif step == 'stop_motors': print('Motors stopped') elif step == 'disarm': print('Drone disarmed')
Count how many print statements run in the loop.
The loop runs 4 times, each step triggers one print statement, so total prints are 4.
