What is the output of this code that reads and prints the altitude sensor data?
class AltitudeSensor: def __init__(self): self.altitude = 100 # meters def read(self): return self.altitude sensor = AltitudeSensor() print(f"Altitude: {sensor.read()} meters")
Look at the value stored in the altitude attribute and what the read method returns.
The AltitudeSensor class sets altitude to 100 in the constructor. The read method returns this value. So the print statement outputs 'Altitude: 100 meters'.
Which option best describes the main role of the flight controller in a drone?
Think about what part controls the drone's movement and balance.
The flight controller is the brain that reads sensors and adjusts motors to keep the drone stable and follow commands.
What error will this motor control code produce when run?
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)
Check the set_speed method and the value passed to it.
The set_speed method raises a ValueError if speed is outside 0-100. Since 120 is passed, it raises the error.
Which option contains the correct syntax to parse GPS coordinates from a dictionary?
gps_data = {'lat': 40.7128, 'lon': -74.0060}
# Choose the correct way to extract latitude and longitudeRemember how to access dictionary values by keys.
Option A correctly accesses dictionary values by keys. Option A uses dot notation which is invalid for dict. Option A has wrong syntax with semicolon. Option A tries to get 'longitude' key which does not exist.
Given this code snippet, what is the total thrust output printed?
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}")
Calculate thrust for each motor and add them up carefully.
Each motor's thrust is speed * 0.5. Speeds are 80,90,85,95. Thrusts: 40,45,42.5,47.5. Sum is 175.0.
