Driving · Robot club · about 15 min
turn_left() and turn_right() by an angle, heading() as a compass, and turning on the spot.
[1 mark]Which way does turn_right(30, angle=90) turn the robot, seen from above?
turn_right is always clockwise and turn_left always anticlockwise, whichever way the robot faces.[1 mark]The robot starts at heading 0 and runs turn_left(30, angle=90). What does heading() say? Give a whole number of degrees.
[1 mark]From heading 0 the robot turns right 90, right 90 again, then left 45. What does heading() say? Give a whole number of degrees.
[1 mark]What does turn_right(40) do, with no angle?
forward(speed): it starts and returns at once. Use it when you want to turn until something happens.[1 mark]A pentagon has five equal sides. What angle should each turn_right be? Give a whole number of degrees.
[1 mark]Put these lines in order to drive a square: each time, drive a side, then turn.
Number the lines 1 to 6 to put them in the right order.
for side in range(4): turn_right(30, angle=90)from bugbot import *connect() forward(60, distance=25)print("home?", position())from bugbot import *
connect()
for side in range(4):
forward(60, distance=25)
turn_right(30, angle=90)
print("home?", position())The drive and the turn are both indented, so both repeat four times. The print is not indented, so it runs once at the end.
[1 mark]After driving a square, the robot is a little away from its start and a few degrees off. Why?
Turn so the robot faces 90 degrees (to the right of where it started), then print facing: and its heading. Do not drive anywhere.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# turn 45 degrees clockwise, then stop
turn_right(30, angle=45)
print("facing:", heading())The hint students can ask for: Turn so the robot faces 90 degrees (east, to the right), then print facing: and its heading. Do not drive anywhere.
from bugbot import *
connect()
turn_right(30, angle=90)
print('facing:', heading())
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.