Bird
Raised Fist0
Drone Programmingprogramming~20 mins

Drone components overview in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Drone Components Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of sensor data reading code

What is the output of this code that reads and prints the altitude sensor data?

Drone Programming
class AltitudeSensor:
    def __init__(self):
        self.altitude = 100  # meters
    def read(self):
        return self.altitude

sensor = AltitudeSensor()
print(f"Altitude: {sensor.read()} meters")
AAltitude: None meters
BAltitude: 0 meters
CAltitude: 100 meters
DError: AttributeError
Attempts:
2 left
💡 Hint

Look at the value stored in the altitude attribute and what the read method returns.

🧠 Conceptual
intermediate
1:30remaining
Purpose of the flight controller

Which option best describes the main role of the flight controller in a drone?

AIt provides GPS location data only.
BIt processes sensor data and controls motors to stabilize and navigate the drone.
CIt charges the drone's battery during flight.
DIt captures photos and videos during flight.
Attempts:
2 left
💡 Hint

Think about what part controls the drone's movement and balance.

🔧 Debug
advanced
2:00remaining
Identify the error in motor control code

What error will this motor control code produce when run?

Drone Programming
class Motor:
    def __init__(self, id):
        self.id = id
        self.speed = 0
    def set_speed(self, speed):
        if speed < 0 or speed > 100:
            raise ValueError("Speed must be 0-100")
        self.speed = speed

motor = Motor(1)
motor.set_speed(120)
print(motor.speed)
A0
B120
CAttributeError: 'Motor' object has no attribute 'speed'
DValueError: Speed must be 0-100
Attempts:
2 left
💡 Hint

Check the set_speed method and the value passed to it.

📝 Syntax
advanced
1:30remaining
Syntax error in GPS data parsing

Which option contains the correct syntax to parse GPS coordinates from a dictionary?

Drone Programming
gps_data = {'lat': 40.7128, 'lon': -74.0060}

# Choose the correct way to extract latitude and longitude
Alatitude, longitude = gps_data['lat'], gps_data['lon']
Blatitude, longitude = gps_data.lat, gps_data.lon
Clatitude, longitude = gps_data['lat'; 'lon']
Dlatitude, longitude = gps_data.get('lat'), gps_data.get('longitude')
Attempts:
2 left
💡 Hint

Remember how to access dictionary values by keys.

🚀 Application
expert
2:30remaining
Calculate total thrust from motor speeds

Given this code snippet, what is the total thrust output printed?

Drone Programming
class Motor:
    def __init__(self, id):
        self.id = id
        self.speed = 0
    def set_speed(self, speed):
        self.speed = speed
    def thrust(self):
        return self.speed * 0.5

motors = [Motor(i) for i in range(4)]
speeds = [80, 90, 85, 95]
for m, s in zip(motors, speeds):
    m.set_speed(s)
total_thrust = sum(m.thrust() for m in motors)
print(f"Total thrust: {total_thrust}")
ATotal thrust: 175.0
BTotal thrust: 175.5
CTotal thrust: 175
DTotal thrust: 350.0
Attempts:
2 left
💡 Hint

Calculate thrust for each motor and add them up carefully.

Practice

(1/5)
1. Which component of a drone is primarily responsible for controlling its flight and processing sensor data?
easy
A. Motor
B. Battery
C. Camera
D. Flight controller

Solution

  1. Step 1: Understand the role of the flight controller

    The flight controller acts like the brain of the drone, managing flight and sensor data.
  2. Step 2: Compare with other components

    Batteries provide power, motors move the drone, and cameras capture images, but do not control flight.
  3. Final Answer:

    Flight controller -> Option D
  4. Quick Check:

    Flight controller = brain of drone [OK]
Hint: Flight controller = drone's brain controlling flight [OK]
Common Mistakes:
  • Confusing battery with controller
  • Thinking motors control flight logic
  • Assuming camera controls flight
2. Which of the following is the correct way to declare a motor speed variable in a drone program using Python?
easy
A. motorSpeed := 100
B. motor-speed = 100
C. motorSpeed = 100
D. motor speed = 100

Solution

  1. Step 1: Check Python variable naming rules

    Variable names cannot have spaces or hyphens; they can use letters, numbers, and underscores.
  2. Step 2: Analyze each option

    motorSpeed = 100 uses camelCase without spaces or hyphens, which is valid. motor-speed = 100 uses a hyphen, invalid. motor speed = 100 has a space, invalid. motorSpeed := 100 uses walrus operator incorrectly for assignment.
  3. Final Answer:

    motorSpeed = 100 -> Option C
  4. Quick Check:

    Valid variable names have no spaces or hyphens [OK]
Hint: Variable names: no spaces or hyphens, use letters/numbers/underscores [OK]
Common Mistakes:
  • Using hyphens in variable names
  • Including spaces in variable names
  • Misusing walrus operator for assignment
3. What will be the output of this Python code snippet simulating battery check?
battery_level = 75
if battery_level >= 50:
    print('Battery sufficient')
else:
    print('Battery low')
medium
A. Battery low
B. Battery sufficient
C. SyntaxError
D. No output

Solution

  1. Step 1: Evaluate the battery_level condition

    The variable battery_level is 75, which is greater than or equal to 50.
  2. Step 2: Determine which print statement runs

    Since 75 >= 50 is true, the code prints 'Battery sufficient'.
  3. Final Answer:

    Battery sufficient -> Option B
  4. Quick Check:

    75 >= 50 means battery sufficient [OK]
Hint: Check if battery_level >= 50 to decide output [OK]
Common Mistakes:
  • Confusing comparison operators
  • Ignoring indentation causing errors
  • Assuming else runs when condition is true
4. Identify the error in this drone motor control code snippet:
def set_motor_speed(speed):
    if speed < 0 or speed > 100:
        print('Invalid speed')
    else
        print(f'Speed set to {speed}')

set_motor_speed(50)
medium
A. Missing colon after else
B. Incorrect function name
C. Invalid comparison operators
D. Wrong print statement syntax

Solution

  1. Step 1: Check syntax after else statement

    In Python, the else statement must end with a colon (:).
  2. Step 2: Identify the missing colon

    The else line lacks a colon, causing a syntax error.
  3. Final Answer:

    Missing colon after else -> Option A
  4. Quick Check:

    else must end with ':' in Python [OK]
Hint: Always put ':' after else in Python [OK]
Common Mistakes:
  • Forgetting colon after else
  • Misnaming functions
  • Using wrong comparison signs
5. You want to program a drone to take a photo only if the battery level is above 30% and the camera is ready. Which Python condition correctly checks this before taking a photo?
battery_level = 45
camera_ready = True

if ???:
    print('Taking photo')
else:
    print('Cannot take photo')
hard
A. battery_level > 30 and camera_ready == True
B. battery_level > 30 or camera_ready == False
C. battery_level <= 30 and camera_ready
D. battery_level >= 30 and not camera_ready

Solution

  1. Step 1: Understand the condition requirements

    The drone should take a photo only if battery_level is above 30 and camera is ready (True).
  2. Step 2: Analyze each option

    battery_level > 30 and camera_ready == True correctly uses 'and' to require both conditions true. battery_level > 30 or camera_ready == False uses 'or' and wrong camera_ready check. battery_level <= 30 and camera_ready checks battery_level less or equal 30, wrong. battery_level >= 30 and not camera_ready requires camera not ready, wrong.
  3. Final Answer:

    battery_level > 30 and camera_ready == True -> Option A
  4. Quick Check:

    Both battery > 30 and camera ready needed [OK]
Hint: Use 'and' to require both battery and camera ready [OK]
Common Mistakes:
  • Using 'or' instead of 'and'
  • Checking wrong battery comparison
  • Negating camera_ready incorrectly
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