Challenge - 5 Problems
Vehicle State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateReading vehicle location coordinates
What is the output of this code snippet that reads the vehicle's latitude and longitude?
Drone Programming
vehicle_location = {'lat': 37.7749, 'lon': -122.4194}
print(f"Latitude: {vehicle_location['lat']}, Longitude: {vehicle_location['lon']}")Attempts:
2 left
💡 Hint
Check the keys used to access latitude and longitude in the dictionary.
✗ Incorrect
The dictionary keys 'lat' and 'lon' correctly access the latitude and longitude values respectively. The f-string formats them with labels and a comma.
❓ Predict Output
intermediateOutput of vehicle attitude reading
Given the vehicle attitude dictionary, what will this code print?
Drone Programming
attitude = {'roll': 0.1, 'pitch': -0.05, 'yaw': 1.57}
print(f"Roll: {attitude['roll']}, Pitch: {attitude['pitch']}, Yaw: {attitude['yaw']}")Attempts:
2 left
💡 Hint
Check the order and keys used in the f-string.
✗ Incorrect
The keys 'roll', 'pitch', and 'yaw' correctly access the attitude values. The f-string prints them with commas separating each value.
❓ Predict Output
advancedBattery percentage calculation output
What is the output of this code that calculates battery percentage from voltage?
Drone Programming
voltage = 11.1 min_voltage = 10.5 max_voltage = 12.6 percentage = int((voltage - min_voltage) / (max_voltage - min_voltage) * 100) print(f"Battery: {percentage}%")
Attempts:
2 left
💡 Hint
Calculate the fraction of voltage between min and max, then multiply by 100.
✗ Incorrect
The formula calculates the battery percentage using int((voltage - min_voltage) / (max_voltage - min_voltage) * 100). Here, (11.1 - 10.5) / (12.6 - 10.5) * 100 = 0.6 / 2.1 * 100 ≈ 28.57, which int() truncates to 28. Therefore, it prints "Battery: 28%".
❓ Predict Output
advancedVehicle attitude dictionary key error
What error does this code raise when trying to access vehicle attitude?
Drone Programming
attitude = {'roll': 0.1, 'pitch': -0.05}
yaw = attitude['yaw']
print(yaw)Attempts:
2 left
💡 Hint
Check if the key 'yaw' exists in the dictionary.
✗ Incorrect
The dictionary does not have the key 'yaw', so accessing attitude['yaw'] raises a KeyError.
🧠 Conceptual
expertInterpreting combined vehicle state output
Given this combined vehicle state dictionary, what is the value of 'battery_status' after running the code?
Drone Programming
vehicle_state = {
'location': {'lat': 40.7128, 'lon': -74.0060},
'attitude': {'roll': 0.0, 'pitch': 0.0, 'yaw': 0.0},
'battery': {'voltage': 11.4, 'min_voltage': 10.5, 'max_voltage': 12.6}
}
voltage = vehicle_state['battery']['voltage']
min_v = vehicle_state['battery']['min_voltage']
max_v = vehicle_state['battery']['max_voltage']
percentage = int((voltage - min_v) / (max_v - min_v) * 100)
battery_status = 'OK' if percentage > 30 else 'LOW'
print(battery_status)Attempts:
2 left
💡 Hint
Calculate the battery percentage and compare with 30.
✗ Incorrect
Battery percentage = (11.4 - 10.5) / (12.6 - 10.5) * 100 = 0.9 / 2.1 * 100 ≈ 42.85, which is greater than 30, so battery_status is 'OK'.
