Talking to each other · Robot club · about 15 min
send(): a broadcast everyone hears; numbers into text.
[1 mark]You call send("hello"). Who hears it?
[1 mark]Which line sends your position in a way another robot can read?
send(f"at {x:.0f},{y:.0f}")send("at x,y")send(position())send(x, y)"at x,y" sends the letters x and y, not the numbers.[1 mark]What does this program print?
x, y = 12.6, 30.4
print(f"at {x:.0f},{y:.0f}")at 13,30
:.0f shows no decimal places, rounding to the nearest whole number: 12.6 becomes 13 and 30.4 becomes 30.
[1 mark]Two robots are not understanding each other. Where do you look first?
[1 mark]You send a question. Is a reply guaranteed?
[1 mark]What type of Python value is every radio message?
Send hello, drive forward 20 cm, then send your position as at <x>,<y> in whole centimetres from the start.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# radio this to every other robot
send('hello')
# pause 1 s (the robot keeps doing what it was told)
wait(1)
print(messages())The hint students can ask for: Send hello, drive forward 20 cm, then send your position as at <x>,<y> (whole centimetres, from the start).
from bugbot import *
connect()
send("hello")
forward(50, distance=20)
x, y = position()
send(f"at {x:.0f},{y:.0f}")
wait(0.5)
print(messages())
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.