Challenge - 5 Problems
Command Acknowledgment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of acknowledgment status check
What is the output of this drone command acknowledgment code snippet?
Drone Programming
ack = {'cmd_id': 101, 'status': 'SUCCESS'}
if ack['status'] == 'SUCCESS':
print(f"Command {ack['cmd_id']} executed successfully.")
else:
print(f"Command {ack['cmd_id']} failed.")Attempts:
2 left
💡 Hint
Check the value of the 'status' key in the acknowledgment dictionary.
✗ Incorrect
The code checks if the 'status' is 'SUCCESS'. Since it is, it prints the success message with the command ID.
🧠 Conceptual
intermediate1:30remaining
Understanding acknowledgment timeout handling
In drone command acknowledgment handling, what is the main purpose of implementing a timeout mechanism?
Attempts:
2 left
💡 Hint
Think about what happens if the drone never sends back an acknowledgment.
✗ Incorrect
Timeout prevents the system from waiting forever and allows it to handle cases where the drone does not respond.
🔧 Debug
advanced2:00remaining
Identify the error in acknowledgment parsing
What error will this code raise when processing the acknowledgment?
Drone Programming
ack = {'cmd_id': 202, 'status': 'FAILURE'}
print(f"Command {ack['command_id']} status: {ack['status']}")Attempts:
2 left
💡 Hint
Check the dictionary keys carefully.
✗ Incorrect
The key 'command_id' does not exist in the dictionary; the correct key is 'cmd_id'. This causes a KeyError.
📝 Syntax
advanced1:30remaining
Syntax error in acknowledgment conditional
Which option fixes the syntax error in this acknowledgment check code?
Drone Programming
if ack['status'] = 'SUCCESS': print('Command succeeded') else: print('Command failed')
Attempts:
2 left
💡 Hint
Remember the difference between assignment and comparison operators.
✗ Incorrect
The single '=' is assignment and causes a syntax error in an if condition. '==' is the correct comparison operator.
🚀 Application
expert2:30remaining
Result of acknowledgment retry logic
Given this retry logic for command acknowledgment, what is the final value of 'attempts' after the loop ends?
Drone Programming
attempts = 0 max_attempts = 3 acknowledged = False while attempts < max_attempts and not acknowledged: attempts += 1 # Simulate acknowledgment received only on 3rd attempt if attempts == 3: acknowledged = True print(attempts)
Attempts:
2 left
💡 Hint
Count how many times the loop runs until acknowledgment is True.
✗ Incorrect
The loop increments attempts each time. On the 3rd attempt, acknowledgment becomes True, so the loop stops after attempts equals 3.