0
0
Drone Programmingprogramming~20 mins

Testing failsafe scenarios in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Failsafe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output when GPS signal is lost?
Consider this drone control snippet that triggers a failsafe when GPS signal is lost. What will be printed?
Drone Programming
def check_gps(signal_strength):
    if signal_strength < 20:
        print("Failsafe activated: Returning to home.")
    else:
        print("GPS signal stable.")

check_gps(15)
AFailsafe activated: Returning to home.
BGPS signal stable.
CError: signal_strength undefined
DFailsafe activated: Landing immediately.
Attempts:
2 left
💡 Hint
Check the condition for signal strength less than 20.
Predict Output
intermediate
2:00remaining
What happens if battery level is exactly at threshold?
This code triggers a failsafe if battery is below 15%. What will it print if battery is exactly 15%?
Drone Programming
def battery_check(level):
    if level < 15:
        print("Failsafe: Land immediately.")
    else:
        print("Battery level sufficient.")

battery_check(15)
ANo output
BFailsafe: Land immediately.
CBattery level sufficient.
DFailsafe: Return to home.
Attempts:
2 left
💡 Hint
Check if the condition includes equality or only less than.
Predict Output
advanced
2:00remaining
What error occurs if failsafe function is called without parameters?
What error will this code raise when calling failsafe() without arguments?
Drone Programming
def failsafe(mode):
    if mode == "return":
        print("Returning to home.")
    elif mode == "land":
        print("Landing immediately.")
    else:
        print("Unknown mode.")

failsafe()
ATypeError: failsafe() missing 1 required positional argument: 'mode'
BNameError: mode is not defined
CNo output
DSyntaxError
Attempts:
2 left
💡 Hint
Check the function definition and how it is called.
🧠 Conceptual
advanced
2:00remaining
Which condition triggers failsafe on sensor failure?
Given a sensor reading variable 'sensor_ok' that is True when sensors work and False when they fail, which condition correctly triggers the failsafe?
A
if sensor_ok = False:
    activate_failsafe()
B
if sensor_ok == False:
    activate_failsafe()
C
if sensor_ok != True:
    activate_failsafe()
D
if sensor_ok == True:
    activate_failsafe()
Attempts:
2 left
💡 Hint
Remember the difference between assignment and comparison.
Predict Output
expert
3:00remaining
What is the output of the failsafe retry loop?
This code tries to reconnect up to 3 times. What will it print?
Drone Programming
def reconnect():
    for attempt in range(1, 4):
        print(f"Attempt {attempt}: Trying to reconnect...")
        if attempt == 2:
            print("Reconnected successfully.")
            break
    else:
        print("Failed to reconnect after 3 attempts.")

reconnect()
A
Attempt 1: Trying to reconnect...
Failed to reconnect after 3 attempts.
B
Attempt 1: Trying to reconnect...
Attempt 2: Trying to reconnect...
Attempt 3: Trying to reconnect...
Failed to reconnect after 3 attempts.
CReconnected successfully.
D
Attempt 1: Trying to reconnect...
Attempt 2: Trying to reconnect...
Reconnected successfully.
Attempts:
2 left
💡 Hint
Check how the break affects the else clause of the loop.