Challenge - 5 Problems
Battery Failsafe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Battery failsafe trigger output
What will be the output of this drone battery monitoring code snippet when battery level is 15%?
Drone Programming
battery_level = 15 if battery_level < 20: print("Warning: Battery low! Initiate failsafe.") else: print("Battery level normal.")
Attempts:
2 left
💡 Hint
Check the condition comparing battery_level with 20.
✗ Incorrect
Since battery_level is 15, which is less than 20, the if condition is true and the warning message is printed.
🧠 Conceptual
intermediate1:30remaining
Failsafe activation condition
Which battery level condition correctly activates the failsafe when battery is critically low?
Attempts:
2 left
💡 Hint
Failsafe should trigger at or below a critical low battery percentage.
✗ Incorrect
Failsafe activates when battery is at or below 10%, so condition 'battery_level <= 10' is correct.
🔧 Debug
advanced2:00remaining
Identify the error in battery failsafe code
What error will this code produce when run?
battery_level = 25
if battery_level < 20
print("Failsafe activated")
Drone Programming
battery_level = 25 if battery_level < 20 print("Failsafe activated")
Attempts:
2 left
💡 Hint
Check the syntax of the if statement.
✗ Incorrect
The if statement is missing a colon ':' at the end of the condition line, causing a SyntaxError.
🚀 Application
advanced2:00remaining
Failsafe behavior with multiple battery checks
Given this code, what will be printed if battery_level is 18?
battery_level = 18
if battery_level < 10:
print("Critical battery! Land immediately.")
elif battery_level < 20:
print("Warning: Battery low. Prepare to land.")
else:
print("Battery level sufficient.")
Drone Programming
battery_level = 18 if battery_level < 10: print("Critical battery! Land immediately.") elif battery_level < 20: print("Warning: Battery low. Prepare to land.") else: print("Battery level sufficient.")
Attempts:
2 left
💡 Hint
Check which condition matches battery_level 18 first.
✗ Incorrect
18 is not less than 10, so first if is false. It is less than 20, so elif is true and prints the warning.
❓ Predict Output
expert3:00remaining
Failsafe loop with battery drain simulation
What is the final output of this code simulating battery drain and failsafe activation?
battery_level = 25
while battery_level > 0:
battery_level -= 7
if battery_level <= 10:
print(f"Failsafe activated at {battery_level}% battery")
break
else:
print("Battery drained without failsafe")
Drone Programming
battery_level = 25 while battery_level > 0: battery_level -= 7 if battery_level <= 10: print(f"Failsafe activated at {battery_level}% battery") break else: print("Battery drained without failsafe")
Attempts:
2 left
💡 Hint
Trace battery_level changes each loop iteration.
✗ Incorrect
battery_level decreases by 7 each loop: 25->18->11->4. At 4 (<=10), failsafe triggers and breaks loop.