Bird
Raised Fist0
Drone Programmingprogramming~20 mins

Why swarms multiply drone capability in Drone Programming - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Swarm Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of swarm coordination message broadcast
Consider a drone swarm where each drone broadcasts a message to all others. What is the output of the following code simulating message counts after one broadcast cycle?
Drone Programming
class Drone:
    def __init__(self, id):
        self.id = id
        self.received_messages = 0

    def broadcast(self, swarm):
        for drone in swarm:
            if drone.id != self.id:
                drone.received_messages += 1

swarm = [Drone(i) for i in range(3)]
for drone in swarm:
    drone.broadcast(swarm)

result = [d.received_messages for d in swarm]
print(result)
A[3, 3, 3]
B[2, 2, 2]
C[1, 1, 1]
D[0, 0, 0]
Attempts:
2 left
💡 Hint
Each drone sends messages to all other drones except itself.
🧠 Conceptual
intermediate
1:30remaining
Why does a drone swarm improve area coverage?
Which reason best explains why a swarm of drones covers a larger area faster than a single drone?
ASwarm drones reduce the need for GPS signals.
BA single drone flies faster than multiple drones combined.
CSwarm drones share batteries to extend flight time.
DMultiple drones can split the area and scan different parts simultaneously.
Attempts:
2 left
💡 Hint
Think about how dividing work helps get it done faster.
🔧 Debug
advanced
2:00remaining
Identify the error in swarm leader election code
This code tries to elect the drone with the highest battery as leader. What error does it cause?
Drone Programming
drones = [{'id': 1, 'battery': 50}, {'id': 2, 'battery': 80}, {'id': 3, 'battery': 30}]
leader = max(drones, key=lambda d: d['battery'])
print(f"Leader is drone {leader['id']}")
AAttributeError because dicts use [] not . to access keys
BSyntaxError due to missing colon in lambda
CTypeError because max() needs a list of numbers
DNo error, prints 'Leader is drone 2'
Attempts:
2 left
💡 Hint
Check how dictionary keys are accessed in Python.
📝 Syntax
advanced
1:30remaining
Find the syntax error in swarm status update
What is wrong with this code snippet updating drone statuses in a swarm?
Drone Programming
statuses = {drone.id: 'active' for drone in swarm if drone.battery > 20}
print(statuses)
AMissing closing bracket '}' for dictionary comprehension
BUsing parentheses instead of square brackets for dictionary keys
CIncorrect indentation of print statement
DMissing colon ':' after 'for' keyword
Attempts:
2 left
💡 Hint
Check if all brackets are properly closed.
🚀 Application
expert
2:30remaining
Calculate total swarm payload capacity
Given a list of drones with individual payload capacities, what is the total payload capacity of the swarm?
Drone Programming
drones = [{'id': 1, 'payload': 5.0}, {'id': 2, 'payload': 7.5}, {'id': 3, 'payload': 6.0}]
total_payload = sum(drone['payload'] for drone in drones)
print(total_payload)
ANone
B3
C18.5
DError due to missing import
Attempts:
2 left
💡 Hint
Add all payload values from each drone.

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

  1. Step 1: Understand the role of multiple drones

    Multiple drones working together can cover more ground and perform tasks faster than one drone alone.
  2. Step 2: Compare individual vs swarm capability

    Individual drones have limited range and tasks, but swarms multiply these by teamwork.
  3. Final Answer:

    Because many drones work together to cover more area and tasks -> Option B
  4. 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

  1. Step 1: Identify correct function call syntax

    Function calls use parentheses with arguments inside, like startSwarm(5).
  2. Step 2: Check other options for syntax errors

    Options A, B, and C use brackets, braces, or missing parentheses which are incorrect.
  3. Final Answer:

    startSwarm(5) -> Option D
  4. 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

  1. 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.
  2. Step 2: Analyze the print statement

    It prints the drone name followed by ' active' for each drone in the list.
  3. Final Answer:

    drone1 active\ndrone2 active\ndrone3 active -> Option C
  4. 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

  1. 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.
  2. Step 2: Verify other parts of the code

    Using range(len(swarm)) is valid, string concatenation with + is correct, and 'swarm' is defined.
  3. Final Answer:

    Missing colon ':' after for loop declaration -> Option A
  4. 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

  1. Step 1: Understand how dividing tasks helps swarms

    Dividing the area into unique sections lets drones work in parallel without overlap, increasing efficiency.
  2. Step 2: Evaluate other options for efficiency

    Random flying or assigning the same area causes overlap and wasted effort; one drone alone is slow.
  3. Final Answer:

    Assign each drone a unique area section and coordinate their paths -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard