Talking to each other · Robot club · about 15 min
messages(): what arrived since you last asked, and who sent it.
[1 mark]What does messages() give you?
[1 mark]What does this program print?
inbox = [("Beacon", "tick 1"), ("Scout", "at 25,55"), ("Beacon", "tick 2")]
for sender, text in inbox:
if sender == "Beacon":
print("heard", sender + ":", text)[1 mark]The Beacon sends a message once a second, the first at 0.1 s. Your program waits 3.2 s and then calls messages(). How many messages does it get?
[1 mark]A polling loop checks messages() but has no wait. What is the problem?
[1 mark]Your program is busy driving for 5 seconds and does not call messages(). What happens to the Beacon's messages?
[1 mark]You call send("hello") and then messages(). Is your own hello in the list?
send goes to every other robot, so you only get what others sentPrint heard <sender>: <text> for each of the Beacon's messages, at least five of them. Do not drive.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() # pause 2 s (the robot keeps doing what it was told) wait(2) print(messages())
Plan your program here, then type it in and press Run.
clock().tick 5 arrives.