Python quick start · Robot club · about 12 min
Lists, len, min and max, slices and looping over the 64 readings of the depth grid.
[1 mark]What does this program print?
speeds = [20, 40, 60] print(speeds[0]) print(len(speeds))
[1 mark]speeds = [20, 40, 60]. Which gives you 60?
speeds[2]speeds[3]speeds[1]speeds(3)[1 mark]How many readings does tof_grid() give you?
[1 mark]What does this program print?
grid = [10, 11, 12, 13, 14, 15] print(grid[2:4])
[1 mark]What does this program print?
readings = [55, 32, 18, 70, 39]
close = 0
for value in readings:
if value < 40:
close = close + 1
print(close, "readings are under 40 cm")[1 mark]What does this program print?
readings = [27.43, 80.0, 45.2]
print("nearest:", round(min(readings), 1))[1 mark]Which readings does grid[24:32] give you?
There is a box on the mat in front of the robot. Print one line saying how far away it is, like nearest: 27, worked out with min() from tof_grid() rather than from distance(). The smallest of all 64 readings is the mat under the robot's nose, 8 cm, so only look at the rows that see straight ahead.
from bugbot import * connect() grid = tof_grid() # your line here
Plan your program here, then type it in and press Run.