📖 Scenario: You are working on a drone project and want to organize information about popular flight controllers. This will help you quickly compare their features and decide which one to use.
🎯 Goal: Create a program that stores flight controller data, sets a filter for minimum supported features, selects controllers meeting the filter, and then displays the filtered list.
📋 What You'll Learn
Create a dictionary with flight controllers and their key features count
Add a minimum feature count filter variable
Use a dictionary comprehension to select controllers meeting the filter
Print the filtered dictionary
💡 Why This Matters
🌍 Real World
Organizing and filtering flight controller data helps drone developers quickly compare options and choose the best controller for their project.
💼 Career
Understanding how to manage and filter data structures is essential for programming tasks in drone software development and embedded systems.
Progress0 / 4 steps
1
Create flight controllers data
Create a dictionary called flight_controllers with these exact entries: 'ArduPilot': 15, 'PX4': 12, 'Betaflight': 8
Drone Programming
Hint
Use curly braces {} to create a dictionary with keys as controller names and values as feature counts.
2
Set minimum feature count filter
Create a variable called min_features and set it to 10 to filter controllers with at least 10 features
Drone Programming
Hint
Just assign the number 10 to the variable min_features.
3
Filter controllers by minimum features
Use a dictionary comprehension to create a new dictionary called filtered_controllers that includes only controllers from flight_controllers with feature counts greater than or equal to min_features
Drone Programming
Hint
Use {name: features for name, features in flight_controllers.items() if features >= min_features} to filter.
4
Display filtered flight controllers
Write a print statement to display the filtered_controllers dictionary
Drone Programming
Hint
Use print(filtered_controllers) to show the result.
Practice
(1/5)
1. Which flight controller is mainly designed for racing drones?
easy
A. PX4
B. ArduPilot
C. Betaflight
D. Mission Planner
Solution
Step 1: Understand flight controller purposes
Betaflight is known for its focus on fast, agile racing drones.
Step 2: Compare with other controllers
ArduPilot and PX4 support many drone types, not just racing.
Final Answer:
Betaflight -> Option C
Quick Check:
Racing drones use Betaflight [OK]
Hint: Betaflight = racing drones, ArduPilot/PX4 = versatile [OK]
Common Mistakes:
Confusing ArduPilot as racing-only
Thinking PX4 is only for racing
Selecting Mission Planner (it's a software, not a controller)
2. Which of the following is the correct way to start the PX4 flight controller using the command line?
easy
A. start px4
B. px4 start
C. px4.launch
D. launch px4
Solution
Step 1: Recall PX4 command syntax
The PX4 flight controller is started with the command px4 start.
Step 2: Check other options
Options like start px4, px4.launch, and launch px4 are incorrect commands.
Final Answer:
px4 start -> Option B
Quick Check:
PX4 starts with 'px4 start' command [OK]
Hint: PX4 command line starts with 'px4 start' [OK]
Common Mistakes:
Reversing command order
Using '.launch' as a command
Confusing with graphical launch commands
3. Given this ArduPilot code snippet, what will be the output?
mode = 'AUTO'
if mode == 'AUTO':
print('Autonomous flight enabled')
else:
print('Manual control active')
medium
A. Autonomous flight enabled
B. Manual control active
C. SyntaxError
D. No output
Solution
Step 1: Check the value of mode variable
The variable mode is set to the string 'AUTO'.
Step 2: Evaluate the if condition
The condition mode == 'AUTO' is true, so the first print statement runs.
Final Answer:
Autonomous flight enabled -> Option A
Quick Check:
mode == 'AUTO' triggers autonomous message [OK]
Hint: Check if condition matches variable value exactly [OK]
Common Mistakes:
Assuming else runs when mode is 'AUTO'
Confusing string case sensitivity
Expecting syntax error from simple if
4. Identify the error in this Betaflight configuration snippet:
def set_pid(p, i, d):
pid = {'P': p, 'I': i, 'D': d}
return pid
config = set_pid(40, 30)
print(config)
medium
A. Missing one argument in set_pid call
B. Incorrect dictionary keys
C. Syntax error in function definition
D. Print statement missing parentheses
Solution
Step 1: Check function parameters and call
The function set_pid requires 3 arguments: p, i, d.
Step 2: Compare with function call
The call set_pid(40, 30) provides only 2 arguments, missing the third.
Final Answer:
Missing one argument in set_pid call -> Option A
Quick Check:
Function needs 3 args but only 2 given [OK]
Hint: Count function args and call parameters carefully [OK]
Common Mistakes:
Assuming default values exist
Thinking dictionary keys are wrong
Ignoring Python 3 print syntax
5. You want to program a PX4 drone to switch between manual and autonomous modes based on a variable mode. Which code snippet correctly implements this logic?
hard
A. if mode != 'MANUAL'
control_manual()
else
control_auto()
B. if mode = 'MANUAL':
control_manual()
else:
control_auto()
C. switch(mode) {
case 'MANUAL': control_manual(); break;
default: control_auto();
}
D. if mode == 'MANUAL':
control_manual()
else:
control_auto()
Solution
Step 1: Check correct Python syntax for condition
The correct code uses if mode == 'MANUAL': which is correct for equality check in Python.
Step 2: Verify function calls and else block
The correct code calls control_manual() if true, else control_auto(), matching the logic.
Final Answer:
if mode == 'MANUAL': control_manual() else: control_auto() -> Option D
Quick Check:
Python uses '==' for comparison, correct if-else structure [OK]
Hint: Use '==' for comparison, not '=' in conditions [OK]
Common Mistakes:
Using '=' instead of '==' in if condition
Using switch-case syntax in Python
Missing colons or indentation in if-else
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.