The answersDownload the PDF
Worksheet

F7.5 Project: the logbook

Files and databases · GCSE · about 25 min

BugBotLab
NameClassDate

What this lesson is about

Log every run to a file, load the file into a table, and find the best run with SQL.

Questions 4 marks in all

  1. [1 mark]In the logbook, why is the file used as well as the database table?

    1. AThe file keeps the runs between sessions; the table is rebuilt from it to query
    2. BThe table cannot hold numbers
    3. CSQL cannot read files
    4. DFiles are required by SQL
  2. [1 mark]logbook.csv has a header line and four runs. How many lines does the file have?

  3. [1 mark]Which query finds the fastest run?

    1. ASELECT run FROM runs ORDER BY cm / seconds DESC
    2. BSELECT run FROM runs ORDER BY cm ASC
    3. CSELECT COUNT(*) FROM runs
    4. DSELECT run FROM runs WHERE seconds = 0
  4. [1 mark]What happens to the logbook if the program opens logbook.csv with mode "w" to add a run?

    1. AEvery earlier run is lost
    2. BThe run is added at the end
    3. CThe file is read
    4. DNothing changes

The task: the logbook

Build the program from the brief. Print runs logged: <n> using SELECT COUNT(*), and fastest: run <n> at <speed> cm/s with the speed rounded to 1 decimal place, using ORDER BY. The task types 28, and starts from the four-run logbook above every time.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

import sqlite3

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f7-5-project-the-logbook/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Add a task name to each run, and report the fastest run of each task.
  2. Refuse to log a run if the robot stopped more than 2 cm short of the distance asked for.
  3. Store the log in two files, runs.csv and robots.csv, and load them into two linked tables.