Competing · Robot club · about 14 min
info(), your own log, and the loop every game program is built from.
[1 mark]A student copies the Sprint and Stop program into the task. It stops with NameError: name 'info' is not defined. Why?
info() only exists in a game, and in a task no game is telling you anythinginfo needs importing separately[1 mark]Which of these are true of a program in a game?
Tick every answer that is true.
info()print() lines[1 mark]Put the four parts of a game loop in order.
Number the lines 1 to 4 to put them in the right order.
Look: read the sensors and what the game saysWait a momentDecideMove[1 mark]What does this program print?
finish_y = 55
for y in [10, 40, 52]:
gap = finish_y - y
if gap > 25:
print(gap, "forward(90)")
elif gap > 4:
print(gap, "forward(30)")
else:
print(gap, "stop")[1 mark]In the game loop, why does each pass end with wait(0.1)?
info() only updates once a second[1 mark]In the task the target is 55 cm up the mat and the red strip starts 5 cm beyond it. position()[1] reads 58. How many cm are you from the red strip?
Same idea, on your own: drive 55 cm up the mat and stop within 5 cm of that point, without crossing into the red strip five centimetres beyond it. Remember position() counts from where the robot started.
from bugbot import *
connect()
# position() counts from the start, so the line is 55 cm up from here
forward(70)
wait(1)
stop()
print("stopped at", position())Plan your program here, then type it in and press Run.