The answersDownload the PDF
Worksheet

F1.4 Errors: syntax, runtime and logic

Programming basics · GCSE · OCR J277 2.3.2, AQA 8525 3.2.11, Edexcel 1CP2 1.2.5 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

Reading an error message, and the three kinds of error by their exam names.

Questions 6 marks in all

  1. [1 mark]print("hello" is missing its closing bracket. What kind of error is this?

    1. ASyntax error
    2. BRuntime error
    3. CLogic error
    4. DIt is not an error
  2. [1 mark]A program runs with no error message, but the robot drives backwards when it should go forwards. What kind of error is this?

    1. ALogic error
    2. BSyntax error
    3. CRuntime error
    4. DNo error: the program finished
  3. [1 mark]A program prints two lines, then crashes on print(10 / 0). What kind of error is this?

    1. ARuntime error
    2. BSyntax error
    3. CLogic error
    4. DIt prints 0
  4. [1 mark]A program has a syntax error on its last line. How many of its lines run?

    1. ANone
    2. BAll the lines before the error
    3. CAll of them
    4. DOnly the last line
  5. [1 mark]Which of these would stop the program with an error message?

    Tick every answer that is true.

    1. Await("two")
    2. Bprin("hi")
    3. Cforward(50, distance=30) when you meant 20
    4. Dstop with no brackets
  6. [1 mark]Put the steps for fixing an error in order.

    Number the lines 1 to 4 to put them in the right order.

    1. Read the error: find the kind and the line number
    2. Look at that line, and the line above if it looks fine
    3. Run again
    4. Change one thing

The task: fix three errors

This program should turn the LED green, wait a second, drive 30 cm forward into the green zone and print arrived. It has one syntax error, one runtime error and one logic error. Fix them one at a time.

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

led("green"
wait("1")
backward(50, distance=30)
print("arrived")

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

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

Challenges

  1. Write a program with a runtime error on its fifth line and nothing wrong before it. Check that the lines before it still run.
  2. Write a program with a logic error that makes the robot drive too far. Swap with a partner and find each other's.
  3. Try print(10 / 0). Which of the three kinds of error is it?