The function adjust_motors uses sensor data to calculate speeds for multiple motors.
Step 2: Determine output type
Since drones have multiple motors, the output is a list or array of speed values for each motor.
Final Answer:
A list or array of motor speed values -> Option B
Quick Check:
Motor speeds = list/array [OK]
Hint: Motor speeds control multiple motors, so output is a list [OK]
Common Mistakes:
Thinking output is a single number
Confusing motor speeds with battery or location
Assuming output is boolean
4. Identify the error in this flight controller code snippet:
def control_flight(sensor_data):
motor_speeds = []
for i in range(4):
motor_speeds.append(sensor_data[i] * 10)
return motor_speeds
sensor_data = [0.5, 0.6, 0.7]
print(control_flight(sensor_data))
medium
A. No error, code runs correctly
B. SyntaxError due to missing colon
C. IndexError because sensor_data has fewer than 4 elements
D. TypeError because sensor_data is not a list
Solution
Step 1: Check sensor_data length vs loop range
The loop runs 4 times (0 to 3), but sensor_data has only 3 elements (indices 0 to 2).
Step 2: Identify error type
Accessing sensor_data[3] causes IndexError because index 3 is out of range.
Final Answer:
IndexError because sensor_data has fewer than 4 elements -> Option C
Quick Check:
Loop index > sensor_data length = IndexError [OK]
Hint: Check list length before indexing in loops [OK]
Common Mistakes:
Assuming code runs without error
Confusing IndexError with SyntaxError
Ignoring list length mismatch
5. You want to program a flight controller to stabilize a drone by adjusting motor speeds based on pitch and roll sensor inputs. Which approach best fits this purpose?
hard
A. Use camera input to adjust motor speeds without sensors
B. Set motor speeds to fixed values ignoring sensor data
C. Only read GPS data to control motor speeds
D. Use sensor data to calculate corrections and update motor speeds dynamically
Solution
Step 1: Understand stabilization needs
Stabilizing requires reading pitch and roll sensors to detect drone tilt.
Step 2: Apply sensor data to motor control
Calculate corrections from sensor data and adjust motor speeds dynamically to balance the drone.
Final Answer:
Use sensor data to calculate corrections and update motor speeds dynamically -> Option D
Quick Check:
Dynamic motor adjustment with sensors = stabilization [OK]
Hint: Stabilize by adjusting motors using sensor feedback [OK]
Common Mistakes:
Ignoring sensor data for motor control
Using fixed motor speeds only
Relying on GPS or camera alone
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.