📖 Scenario: You are working with a team of drones that can work together as a swarm. Each drone can perform simple tasks, but when they work together, they can do much more. You want to understand how combining their efforts multiplies their capability.
🎯 Goal: Build a simple program that shows how multiple drones working together can cover more area than a single drone.
📋 What You'll Learn
Create a dictionary called drones with drone names as keys and their individual coverage area as values.
Create a variable called swarm_size to represent how many drones are in the swarm.
Use a for loop with variables drone and area to iterate over drones.items() and calculate total coverage.
Print the total coverage area of the swarm.
💡 Why This Matters
🌍 Real World
Drone swarms are used in agriculture, search and rescue, and delivery to cover large areas efficiently.
💼 Career
Understanding how to program and calculate swarm capabilities is important for drone software developers and robotics engineers.
Progress0 / 4 steps
1
DATA SETUP: Create the drones dictionary
Create a dictionary called drones with these exact entries: 'DroneA': 5, 'DroneB': 7, 'DroneC': 6. Each value represents the coverage area of that drone.
Drone Programming
Hint
Use curly braces {} to create a dictionary with keys and values.
2
CONFIGURATION: Define the swarm size
Create a variable called swarm_size and set it to 3 to represent the number of drones in the swarm.
Drone Programming
Hint
Just assign the number 3 to the variable swarm_size.
3
CORE LOGIC: Calculate total coverage area
Create a variable called total_coverage and set it to 0. Then use a for loop with variables drone and area to iterate over drones.items(). Inside the loop, add each area to total_coverage.
Drone Programming
Hint
Start with zero coverage, then add each drone's area inside the loop.
4
OUTPUT: Print the total coverage area
Write a print statement to display the text Total swarm coverage area: followed by the value of total_coverage.
Drone Programming
Hint
Use an f-string to combine text and the variable total_coverage in the print statement.
Practice
(1/5)
1. Why do drone swarms multiply the capability of individual drones?
easy
A. Because drones in swarms use less battery
B. Because many drones work together to cover more area and tasks
C. Because each drone flies faster alone
D. Because swarms reduce the number of drones needed
Solution
Step 1: Understand the role of multiple drones
Multiple drones working together can cover more ground and perform tasks faster than one drone alone.
Step 2: Compare individual vs swarm capability
Individual drones have limited range and tasks, but swarms multiply these by teamwork.
Final Answer:
Because many drones work together to cover more area and tasks -> Option B
Quick Check:
Swarms multiply capability by teamwork = C [OK]
Hint: Think teamwork increases power, not speed or battery alone [OK]
Common Mistakes:
Confusing speed with capability
Assuming battery use decreases in swarms
Thinking swarms reduce drone count
2. Which of the following is the correct syntax to start a swarm of drones in a drone programming language?
easy
A. startSwarm 5
B. start_swarm[5]
C. startSwarm{5}
D. startSwarm(5)
Solution
Step 1: Identify correct function call syntax
Function calls use parentheses with arguments inside, like startSwarm(5).
Step 2: Check other options for syntax errors
Options A, B, and C use brackets, braces, or missing parentheses which are incorrect.
Final Answer:
startSwarm(5) -> Option D
Quick Check:
Function call syntax = parentheses ( ) [OK]
Hint: Function calls always use parentheses ( ) [OK]
Common Mistakes:
Using brackets [] instead of parentheses
Using braces {} instead of parentheses
Omitting parentheses for function calls
3. What will be the output of this code snippet controlling a drone swarm?
swarm = ["drone1", "drone2", "drone3"]
for drone in swarm:
print(f"{drone} active")
medium
A. drone1\ndrone2\ndrone3
B. drone active\ndrone active\ndrone active
C. drone1 active\ndrone2 active\ndrone3 active
D. Error: swarm is not defined
Solution
Step 1: Understand the loop over the swarm list
The for loop goes through each drone name in the list and assigns it to the variable drone.
Step 2: Analyze the print statement
It prints the drone name followed by ' active' for each drone in the list.
Final Answer:
drone1 active\ndrone2 active\ndrone3 active -> Option C
Quick Check:
Loop prints each drone name + ' active' = A [OK]
Hint: Loop prints each item with ' active' appended [OK]
Common Mistakes:
Printing the variable name instead of its value
Missing the f-string formatting
Assuming an error due to variable name
4. Find the error in this drone swarm control code:
swarm = ["droneA", "droneB"]
for i in range(len(swarm))
print(swarm[i] + " ready")
medium
A. Missing colon ':' after for loop declaration
B. Using range instead of direct iteration
C. Incorrect string concatenation
D. Variable 'swarm' is not defined
Solution
Step 1: Check for syntax errors in the for loop
The for loop line is missing a colon ':' at the end, which is required in Python syntax.
Step 2: Verify other parts of the code
Using range(len(swarm)) is valid, string concatenation with + is correct, and 'swarm' is defined.
Final Answer:
Missing colon ':' after for loop declaration -> Option A
Quick Check:
Python loops need ':' after declaration = A [OK]
Hint: Look for missing colons in loops and conditionals [OK]
Common Mistakes:
Ignoring missing colon syntax error
Thinking range(len()) is wrong
Confusing string concatenation syntax
5. You want to program a drone swarm to divide a large area into equal parts and assign each drone a section. Which approach best multiplies swarm capability?
hard
A. Assign each drone a unique area section and coordinate their paths
B. Let all drones fly randomly and cover the area by chance
C. Use only one drone to map the entire area first
D. Assign all drones the same area to ensure coverage
Solution
Step 1: Understand how dividing tasks helps swarms
Dividing the area into unique sections lets drones work in parallel without overlap, increasing efficiency.
Step 2: Evaluate other options for efficiency
Random flying or assigning the same area causes overlap and wasted effort; one drone alone is slow.
Final Answer:
Assign each drone a unique area section and coordinate their paths -> Option A
Quick Check:
Divide and coordinate tasks = best swarm use = B [OK]
Hint: Divide tasks uniquely for efficient swarm work [OK]
Common Mistakes:
Thinking random flying covers area faster
Assigning same area wastes drone effort
Using one drone defeats swarm advantage
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.