Challenge - 5 Problems
Swarm Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Each drone sends messages to all other drones except itself.
✗ Incorrect
Each of the 3 drones sends a message to the other 2 drones, so each drone receives 2 messages total.
🧠 Conceptual
intermediate1: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?
Attempts:
2 left
💡 Hint
Think about how dividing work helps get it done faster.
✗ Incorrect
Multiple drones can divide the area into parts and scan them at the same time, speeding up coverage.
🔧 Debug
advanced2: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']}")Attempts:
2 left
💡 Hint
Check how dictionary keys are accessed in Python.
✗ Incorrect
The code tries to access dictionary keys with dot notation, which causes AttributeError.
📝 Syntax
advanced1: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)Attempts:
2 left
💡 Hint
Check if all brackets are properly closed.
✗ Incorrect
The dictionary comprehension is missing the closing '}' bracket before the print statement.
🚀 Application
expert2: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)Attempts:
2 left
💡 Hint
Add all payload values from each drone.
✗ Incorrect
Summing 5.0 + 7.5 + 6.0 equals 18.5, the total payload capacity.