📖 Scenario: You are programming a drone that needs to land safely and then turn off its motors to save power. This is important after completing a flight mission.
🎯 Goal: You will write a simple program to make the drone land and then disarm its motors.
📋 What You'll Learn
Create a variable called altitude with the starting height of the drone.
Create a variable called landing_height to represent the height at which the drone should stop descending.
Use a while loop to reduce the altitude until it reaches landing_height.
After landing, set a variable called motors_armed to False to disarm the drone.
Print the final altitude and the motors status.
💡 Why This Matters
🌍 Real World
Drones must land safely and turn off motors to save battery and avoid accidents.
💼 Career
Understanding how to control drone states and use loops is essential for drone programming and robotics jobs.
Progress0 / 4 steps
1
Set the initial altitude
Create a variable called altitude and set it to 100 to represent the drone's starting height in meters.
Drone Programming
Hint
Use a simple assignment like altitude = 100.
2
Set the landing height
Create a variable called landing_height and set it to 0 to represent the ground level where the drone should stop descending.
Drone Programming
Hint
Set landing_height to zero because the ground is at height zero.
3
Land the drone by lowering altitude
Use a while loop with the condition altitude > landing_height. Inside the loop, decrease altitude by 10 each time to simulate the drone descending.
Drone Programming
Hint
Use while altitude > landing_height: and inside reduce altitude by 10 with altitude -= 10.
4
Disarm motors and print status
Create a variable called motors_armed and set it to False to disarm the drone after landing. Then print the final altitude and the motors_armed status.
Drone Programming
Hint
After the loop, set motors_armed = False and print both altitude and motors_armed.
Practice
(1/5)
1. What is the main purpose of disarm() in drone programming?
easy
A. To increase the drone's speed
B. To make the drone take off automatically
C. To stop the drone's motors and prevent propeller movement
D. To change the drone's flight path
Solution
Step 1: Understand the function of disarm()
The disarm() function is used to stop the drone's motors, which stops the propellers from spinning.
Step 2: Compare with other options
Taking off, increasing speed, or changing flight path are not related to disarming.
Final Answer:
To stop the drone's motors and prevent propeller movement -> Option C
Quick Check:
Disarm = stop motors [OK]
Hint: Disarm always means stop motors and propellers [OK]
Common Mistakes:
Confusing disarm with takeoff
Thinking disarm changes flight path
Assuming disarm increases speed
2. Which of the following is the correct syntax to land a drone using a function named land()?
easy
A. land()
B. land[]
C. land{}
D. land;
Solution
Step 1: Recall function call syntax
In most programming languages, calling a function uses parentheses after the function name, like land().
Step 2: Check other options
Square brackets, curly braces, or semicolons alone are not valid for calling functions.