Project: the revision robot

A robot that asks you questions, marks your answers and tells you what to revise.

F13.9Exam preparationGCSE25 min

Do this lesson in the simulator

The last task of the course builds something you can use for the rest of it: a robot that tests you. It holds a bank of questions, asks them, marks your answers, keeps the ones you got wrong and asks those again, and tells you which topic to revise next. It is retrieval practice (lesson F13.8) with a buzzer.

It also happens to use nearly everything you have learned: lists and records, loops, selection, string handling, input, functions and the robot itself.

What it does

  1. Ask each question in the bank in turn.
  2. Read the answer, and mark it ignoring capitals and spaces at the ends.
  3. Say whether it was right, and if not, give the answer.
  4. Sound a high note for right and a low one for wrong, and set the LED green or red.
  5. At the end, print the score and the topic with the most wrong answers.

The question bank

Each question is a record with a topic, a question and an answer, so a new one is one line:

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

BANK = [
    {"topic": "Networks", "q": "What does DNS turn a domain name into?", "a": "an IP address"},
    {"topic": "Data", "q": "How many bits in a byte?", "a": "8"},
]
for item in BANK:
    print(f"[{item['topic']}] {item['q']}")

Run this in the simulator

Marking an answer

A marker that only accepts an exact match is useless: 8 and An IP address are both right. Clean both sides before comparing:

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

def same(given, wanted):
    return given.strip().lower() == wanted.strip().lower()

print(same(" An IP Address ", "an ip address"), same("7", "8"))

Run this in the simulator

Plan it first

  • a function to ask one question and return True or False;
  • a loop over the bank, counting the score and collecting the ones that were wrong;
  • a second pass over the wrong ones, if there are any;
  • a count of wrong answers per topic, then the worst one;
  • the sounds, the LED, and the report at the end.

Task: the revision robot

Ask every question in BANK in turn. For each one, print [<topic>] <question>, read the answer with input(), and mark it ignoring capitals and spaces at the ends. Print right for a correct answer, or wrong, it is <answer>. Play a 880 Hz note for right and 220 Hz for wrong, each 0.2 seconds. At the end print score: <n> of <total> and revise: <topic>, the topic with the most wrong answers, then set the LED green if you scored more than half and red if not. The answers are typed for you.

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

BANK = [
    {"topic": "Networks", "q": "What does DNS turn a domain name into?", "a": "an IP address"},
    {"topic": "Data", "q": "How many bits in a byte?", "a": "8"},
    {"topic": "Networks", "q": "Which protocol sends email?", "a": "SMTP"},
    {"topic": "Security", "q": "What does a firewall check?", "a": "traffic"},
]

Challenges

  1. Ask the wrong ones again at the end, until they are all right.
  2. Add your own questions from your weakest topic, and run it before school.
  3. Save the score to a file each time, so you can see whether you are improving.