📖 Scenario: You are working on programming a drone to fly safely. Before flying the real drone, you want to test its behavior in a simulation to avoid crashes that could damage the drone or cause accidents.
🎯 Goal: Build a simple simulation that checks if the drone's speed is safe before flying. If the speed is too high, the simulation warns you to slow down, preventing a costly crash.
📋 What You'll Learn
Create a variable called drone_speeds with exact speeds for three test flights: 5, 15, and 25
Create a variable called max_safe_speed set to 20
Use a for loop with variable speed to check each speed in drone_speeds
Inside the loop, use an if statement to print "Safe speed: {speed}" if speed is less than or equal to max_safe_speed
Otherwise, print "Warning! Speed {speed} too high! Slow down."
Print the results exactly as specified
💡 Why This Matters
🌍 Real World
Simulating drone flight speeds helps engineers test safety before flying real drones, saving money and preventing accidents.
💼 Career
Drone programmers and engineers use simulations to ensure drones operate safely under different conditions.
Progress0 / 4 steps
1
Create the drone speeds data
Create a list called drone_speeds with these exact values: 5, 15, and 25
Drone Programming
Hint
Use square brackets to create a list and separate numbers with commas.
2
Set the maximum safe speed
Create a variable called max_safe_speed and set it to 20
Drone Programming
Hint
Just assign the number 20 to the variable max_safe_speed.
3
Check each speed with a loop and condition
Use a for loop with variable speed to go through drone_speeds. Inside the loop, use an if statement to check if speed is less than or equal to max_safe_speed. If yes, print "Safe speed: {speed}". Otherwise, print "Warning! Speed {speed} too high! Slow down."
Drone Programming
Hint
Use a for loop and an if-else statement to print the correct message for each speed.
4
Display the simulation results
Run the program to print the safety messages for each speed in drone_speeds as specified in the previous step.
Drone Programming
Hint
Make sure your print statements match exactly the expected output.
Practice
(1/5)
1. Why is simulation important before flying a drone with new code?
easy
A. It makes the drone fly faster in real life.
B. It automatically fixes all software bugs.
C. It replaces the need for any real drone testing.
D. It helps find errors without risking the drone crashing.
Solution
Step 1: Understand the purpose of simulation
Simulation runs the drone code in a safe virtual environment to check for errors.
Step 2: Compare simulation benefits to real flight risks
By testing in simulation, we avoid crashing the real drone and losing expensive hardware.
Final Answer:
It helps find errors without risking the drone crashing. -> Option D
Quick Check:
Simulation prevents crashes = B [OK]
Hint: Simulation tests safely before real flights [OK]
Common Mistakes:
Thinking simulation makes drones fly faster
Believing simulation replaces all real tests
Assuming simulation fixes bugs automatically
2. Which of the following is the correct way to start a drone simulation in Python?
easy
A. simulate.start()
B. simulation.run()
C. start_simulation()
D. runSimulation()
Solution
Step 1: Identify the correct function name
The standard function to start simulation is named start_simulation() using snake_case in Python.
Step 2: Check other options for syntax or naming errors
Options B, C, and D use incorrect method names or camelCase not typical in Python.
Final Answer:
start_simulation() -> Option C
Quick Check:
Python functions use snake_case = A [OK]
Hint: Python uses snake_case for functions [OK]
Common Mistakes:
Using camelCase function names in Python
Calling methods on undefined objects
Confusing simulation object names
3. What will be the output of this simulation code snippet?
def simulate_crash_check(speed):
if speed > 10:
return "Crash risk detected"
else:
return "Safe to fly"
print(simulate_crash_check(8))
medium
A. "Safe to fly"
B. None
C. SyntaxError
D. "Crash risk detected"
Solution
Step 1: Check the input value against the condition
The input speed is 8, which is not greater than 10, so the else branch runs.
Step 2: Determine the returned string
The else branch returns "Safe to fly" which is printed.