Strings, lists and records · GCSE · about 25 min
Look in eight directions, store the survey as records, report on it and head for open space.
[1 mark]Why plan what one record looks like before writing the survey loop?
[1 mark]What does this program print?
survey = [{"direction": 0, "distance": 31.0}, {"direction": 45, "distance": 42.5}, {"direction": 90, "distance": 51.0}]
total = 0
for r in survey:
total = total + r["distance"]
print(total / len(survey))[1 mark]What does this program print?
survey = [{"direction": 0, "distance": 31.0}, {"direction": 45, "distance": 42.5}, {"direction": 90, "distance": 51.0}]
open_count = 0
for r in survey:
if r["distance"] > 40:
open_count = open_count + 1
print(open_count)[1 mark]Why test the report on a small made-up survey before using the robot's data?
Do the survey from the brief. Print the table, then report lines in exactly this shape (these are the numbers a correct program gets in this room): Then turn to face the farthest direction and play a note.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
survey = []
for i in range(8):
turn_right(30, angle=45)Plan your program here, then type it in and press Run.
open to each record, True or False, and use it for the count.