📖 Scenario: You are programming a group of drones that need to share messages with each other to coordinate their tasks. Each drone has a unique ID and can send messages to other drones in the group.
🎯 Goal: Build a simple program that stores messages sent between drones and shows the messages received by each drone.
📋 What You'll Learn
Create a dictionary called drones with drone IDs as keys and empty lists as values to hold messages.
Create a variable called message with the text to send.
Write a loop that sends the message from one drone to another by adding it to the receiver's message list.
Print the messages received by each drone.
💡 Why This Matters
🌍 Real World
Drones often need to share information like location, status, or commands to work together safely and efficiently.
💼 Career
Understanding how to manage communication between devices is important for roles in robotics, automation, and IoT (Internet of Things) development.
Progress0 / 4 steps
1
Set up drones with empty message lists
Create a dictionary called drones with these exact keys: "drone1", "drone2", and "drone3". Each key should have an empty list [] as its value.
Drone Programming
Hint
Use curly braces {} to create a dictionary. Each drone ID is a key with an empty list [] as the value.
2
Create a message to send
Create a variable called message and set it to the string "Hello from drone1".
Drone Programming
Hint
Use = to assign the string to the variable message.
3
Send the message from drone1 to drone2 and drone3
Use a for loop with the variable receiver to go through the list ["drone2", "drone3"]. Inside the loop, add the message to the list of messages for each receiver in the drones dictionary.
Drone Programming
Hint
Use append() to add the message to each receiver's list.
4
Show messages received by each drone
Use a for loop with variables drone and messages to go through drones.items(). Inside the loop, print the drone ID and its messages in this exact format: "drone1 received: []".
Drone Programming
Hint
Use an f-string to format the print output exactly as shown.
Practice
(1/5)
1. What is the main purpose of communication between drones in a fleet?
easy
A. To share important information and coordinate tasks
B. To recharge each other's batteries
C. To change their physical appearance
D. To compete for the strongest signal
Solution
Step 1: Understand drone communication purpose
Drones communicate to share data and work together efficiently.
Step 2: Identify correct purpose from options
Only To share important information and coordinate tasks mentions sharing information and coordination, which matches the purpose.
Final Answer:
To share important information and coordinate tasks -> Option A
Quick Check:
Communication = Share info and coordinate [OK]
Hint: Communication means sharing info, not physical changes [OK]
Common Mistakes:
Thinking drones recharge each other
Confusing communication with appearance changes
Assuming drones compete instead of cooperate
2. Which of the following is the correct way to send a message from drone A to drone B in drone_programming?
easy
A. send_message(droneA, droneB, 'Hello')
B. droneB.receive_message(droneA.send_message('Hello'))
C. droneA.send_message('Hello').to(droneB)
D. droneA.message('Hello') -> droneB
Solution
Step 1: Understand message sending syntax
In drone_programming, a drone sends a message by calling send_message, and the receiver uses receive_message.
Step 2: Check which option matches this syntax
droneB.receive_message(droneA.send_message('Hello')) shows droneA sending and droneB receiving correctly.
Final Answer:
<code>droneB.receive_message(droneA.send_message('Hello'))</code> -> Option B
Quick Check:
Send then receive method call = droneB.receive_message(droneA.send_message('Hello')) [OK]
Hint: Send message from sender, receive on receiver drone [OK]