Bird
Raised Fist0
Drone Programmingprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of testing failsafe scenarios in drone programming?
easy
A. To add more features to the drone's camera
B. To improve the drone's speed and flight time
C. To ensure the drone handles problems safely and avoids crashes
D. To make the drone fly higher than usual

Solution

  1. Step 1: Understand failsafe scenarios

    Failsafe scenarios are tests to check how the drone reacts to problems like lost connection or low battery.
  2. Step 2: Identify the main goal

    The main goal is to keep the drone safe and avoid crashes during these problems.
  3. Final Answer:

    To ensure the drone handles problems safely and avoids crashes -> Option C
  4. Quick Check:

    Failsafe = safety first [OK]
Hint: Failsafe means safety during problems [OK]
Common Mistakes:
  • Confusing failsafe with performance improvements
  • Thinking failsafe adds new features
  • Assuming failsafe makes drone fly higher
2. Which of the following code snippets correctly simulates a low battery failsafe check in drone programming?
easy
A. if battery_level < 20: initiate_landing()
B. if battery_level > 20: initiate_landing()
C. if battery_level == 100: initiate_landing()
D. if battery_level != 20: initiate_landing()

Solution

  1. Step 1: Understand the battery check condition

    Low battery means battery level is less than a safe threshold, here 20%.
  2. Step 2: Match condition to code

    Only 'if battery_level < 20:' correctly checks for low battery to start landing.
  3. Final Answer:

    if battery_level < 20: initiate_landing() -> Option A
  4. Quick Check:

    Low battery = less than 20% [OK]
Hint: Check if battery is below threshold to trigger landing [OK]
Common Mistakes:
  • Using greater than instead of less than
  • Checking for exact battery value
  • Using not equal instead of less than
3. Given the code below simulating a lost connection failsafe, what will be printed?
connection_status = "lost"
if connection_status == "lost":
    print("Return to home activated")
else:
    print("Continue flying")
medium
A. Return to home activated
B. Continue flying
C. No output
D. SyntaxError

Solution

  1. Step 1: Check the value of connection_status

    The variable connection_status is set to "lost".
  2. Step 2: Evaluate the if condition

    The condition 'connection_status == "lost"' is true, so the first print runs.
  3. Final Answer:

    Return to home activated -> Option A
  4. Quick Check:

    Lost connection triggers return home [OK]
Hint: Match variable value to if condition [OK]
Common Mistakes:
  • Confusing else output with if output
  • Assuming no output if condition true
  • Thinking code has syntax error
4. The following code is meant to trigger an emergency landing if the drone loses GPS signal, but it does not work as expected. What is the error?
gps_signal = False
if gps_signal = False:
    emergency_landing()
medium
A. The variable gps_signal is not defined
B. Missing parentheses after emergency_landing
C. gps_signal should be True to trigger landing
D. Using assignment '=' instead of comparison '==' in the if condition

Solution

  1. Step 1: Identify the if condition syntax

    The code uses 'if gps_signal = False:', which assigns False instead of comparing.
  2. Step 2: Correct the comparison operator

    It should be 'if gps_signal == False:' to check the value properly.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in the if condition -> Option D
  4. Quick Check:

    Use '==' for comparison, not '=' [OK]
Hint: Use '==' to compare, '=' to assign [OK]
Common Mistakes:
  • Confusing '=' and '==' in conditions
  • Forgetting parentheses on function calls
  • Assuming variable is undefined
5. You want to test a failsafe scenario where the drone must land immediately if either the battery is below 15% or the GPS signal is lost. Which code correctly implements this logic?
battery_level = 10
gps_signal = False
# Choose the correct condition to trigger landing
if _____:
    emergency_landing()
hard
A. battery_level < 15 and gps_signal == False
B. battery_level < 15 or gps_signal == False
C. battery_level > 15 or gps_signal == True
D. battery_level > 15 and gps_signal == True

Solution

  1. Step 1: Understand the condition requirements

    The drone should land if battery is below 15% OR GPS signal is lost (False).
  2. Step 2: Match logical operator to condition

    Use 'or' because either condition triggers landing, so 'battery_level < 15 or gps_signal == False'.
  3. Final Answer:

    battery_level < 15 or gps_signal == False -> Option B
  4. Quick Check:

    Use OR for either condition triggers landing [OK]
Hint: Use OR to combine multiple failsafe triggers [OK]
Common Mistakes:
  • Using AND instead of OR
  • Checking for battery > 15 instead of < 15
  • Confusing GPS signal True/False meaning
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard