📖 Scenario: You are programming a drone to help in search and rescue missions. The drone needs to scan an area and identify locations where people might be trapped. Each location has a signal strength indicating the likelihood of a person being there.
🎯 Goal: Build a program that stores locations with their signal strengths, sets a threshold to decide which locations need rescue, filters those locations, and then prints the list of locations that require immediate attention.
📋 What You'll Learn
Create a dictionary called locations with exact keys and signal strength values
Create a variable called threshold with the exact value 70
Use a dictionary comprehension to create a new dictionary called rescue_needed with locations having signal strength greater than or equal to threshold
Print the rescue_needed dictionary
💡 Why This Matters
🌍 Real World
Drones help rescue teams by quickly identifying areas where people might be trapped using signal strengths or sensor data.
💼 Career
Understanding how to filter and process data is essential for programming drones and other autonomous devices in emergency response roles.
Progress0 / 4 steps
1
DATA SETUP: Create the locations dictionary
Create a dictionary called locations with these exact entries: 'Zone A': 65, 'Zone B': 80, 'Zone C': 55, 'Zone D': 90, 'Zone E': 40
Drone Programming
Hint
Use curly braces {} to create a dictionary with keys as zone names and values as signal strengths.
2
CONFIGURATION: Set the signal strength threshold
Create a variable called threshold and set it to the integer 70
Drone Programming
Hint
Just assign the number 70 to the variable threshold.
3
CORE LOGIC: Filter locations needing rescue
Use a dictionary comprehension to create a new dictionary called rescue_needed that includes only the locations from locations where the signal strength is greater than or equal to threshold
Drone Programming
Hint
Use {zone: strength for zone, strength in locations.items() if strength >= threshold} to filter the dictionary.
4
OUTPUT: Print the rescue_needed dictionary
Write a print statement to display the rescue_needed dictionary
Drone Programming
Hint
Use print(rescue_needed) to show the filtered dictionary.
Practice
(1/5)
1. What is the main purpose of a drone programmed for search and rescue assistance?
easy
A. To find missing persons and send their location quickly
B. To deliver packages to remote areas
C. To take aerial photos for tourism
D. To monitor weather patterns
Solution
Step 1: Understand the role of search and rescue drones
These drones are designed to locate missing people or targets in emergency situations.
Step 2: Identify the key function
The main function is to find and report the location quickly to help rescue teams.
Final Answer:
To find missing persons and send their location quickly -> Option A
Quick Check:
Search and rescue = find and report location [OK]
Hint: Search and rescue drones find and report targets fast [OK]
Common Mistakes:
Confusing delivery drones with rescue drones
Thinking drones only take photos
Assuming drones monitor weather in rescue missions
2. Which of the following is the correct syntax to start a drone's search function in drone programming?
easy
A. startSearch()
B. search.start()
C. begin_search
D. searchStart[]
Solution
Step 1: Identify correct function call syntax
Functions are called with parentheses like startSearch().
Step 2: Check other options for syntax errors
search.start() is method call but not standard here; begin_search lacks parentheses; searchStart[] uses brackets incorrectly.
Final Answer:
startSearch() -> Option A
Quick Check:
Function calls use parentheses () [OK]
Hint: Function calls always use parentheses () [OK]
Common Mistakes:
Omitting parentheses when calling functions
Using brackets [] instead of parentheses
Confusing method call syntax with function call
3. What will the following drone program output if the target is found at coordinates (10, 20)?
def search_area():
target = (10, 20)
found = True
if found:
return f"Target located at {target}"
else:
return "Target not found"
print(search_area())
medium
A. Target not found
B. Error: target undefined
C. Target located at (10, 20)
D. None
Solution
Step 1: Analyze the function logic
The variable found is True, so the if condition is met.
Step 2: Determine the returned string
The function returns the string with the target coordinates formatted inside.
Final Answer:
Target located at (10, 20) -> Option C
Quick Check:
found=True returns target location string [OK]
Hint: If found is True, function returns location string [OK]
Common Mistakes:
Assuming found is False and returning 'Target not found'
Confusing tuple printing with string output
Expecting an error due to variable scope
4. Identify the error in this drone search code snippet:
D. Using assignment '=' instead of comparison '==' in if condition
Solution
Step 1: Check the if condition syntax
The condition uses '=' which assigns value, but it should compare using '=='.
Step 2: Verify other parts of the code
Print statements have parentheses, function is called, and variable is defined correctly.
Final Answer:
Using assignment '=' instead of comparison '==' in if condition -> Option D
Quick Check:
Use '==' for comparison in if statements [OK]
Hint: Use '==' to compare, '=' is for assignment [OK]
Common Mistakes:
Confusing '=' with '==' in conditions
Forgetting to call the function
Missing parentheses in print (Python 3)
5. You want a drone to scan multiple zones and report all found targets with their locations. Which code snippet correctly collects and returns all found targets in a dictionary with zone names as keys?
Options:
A)
def scan_zones(zones):
results = {}
for zone in zones:
found = scan(zone)
if found:
results[zone] = found
return results
B)
def scan_zones(zones):
results = []
for zone in zones:
found = scan(zone)
if found:
results.append({zone: found})
return results
C)
def scan_zones(zones):
results = {}
for zone in zones:
found = scan(zone)
results[zone] = found
return results
D)
def scan_zones(zones):
results = {}
for zone in zones:
if scan(zone):
results.append(zone)
return results
hard
A. Collects found targets in a list of dictionaries, not a single dict
B. Collects found targets in a dictionary with zone keys correctly
C. Adds all zones including those without targets (found may be False)
D. Uses append on a dictionary, which causes an error
Solution
Step 1: Understand the goal
We want a dictionary with zones as keys and found targets as values, only if found.
Step 2: Analyze each option
The snippet that adds only found targets to a dict is correct; the one that uses a list of dicts produces the wrong structure; the one that adds all zones includes those without targets; the one that tries to append to a dict causes an error.
Final Answer:
Collects found targets in a dictionary with zone keys correctly -> Option B
Quick Check:
Dict with keys for found targets only = Collects found targets in a dictionary with zone keys correctly [OK]
Hint: Use dict and add only found targets with keys [OK]
Common Mistakes:
Adding all zones even if no target found
Using list instead of dictionary for key-value pairs
Trying to append to a dictionary (invalid)
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.