The worksheetDownload the PDF
Answers

F13.4 Programming questions

Exam preparation · GCSE · about 20 min

BugBotLab

What this lesson is about

Taking a question apart, the jobs that come up again and again, and how the marks are given.

Questions 5 marks in all

  1. [1 mark]You cannot finish a programming question. What is the best thing to do?

    1. AWrite what is left as comments or pseudocode
    2. BLeave it blank
    3. CRub out what you have
    4. DCopy an earlier answer
    Answer: A. Marks are given in steps, and a correct approach scores.
  2. [1 mark]Which of these earns marks in a written programming answer?

    1. AMeaningful variable names and clear structure
    2. BVery short variable names
    3. CNo comments at all
    4. DPerfect punctuation
    Answer: A. The marker must be able to follow what you meant.
  3. [1 mark]A question says to reject an input over 60. What is that worth?

    1. AA mark: handle the failure case
    2. BNothing
    3. COnly if the program runs
    4. DA mark only in an on-screen exam
    Answer: A. Every rule in the question usually carries a mark.
  4. [1 mark]What does this program print?

    done = 0
    steps = 0
    while done < 32:
        step = min(7, 32 - done)
        done = done + step
        steps = steps + 1
    print(steps, done)
    Answer:
    5 32

    Four steps of 7 and a last step of 4.

  5. [1 mark]What should you do before writing any code in a long question?

    1. AUnderline the inputs, outputs and rules
    2. BWrite the last line first
    3. CChoose variable names for everything
    4. DCount the marks
    Answer: A. Then write the structure: input, process, output.

The task: an exam-style program

Write the program for this question. The robot must drive far centimetres in steps of step centimetres, where the last step is whatever is left over. After each step, print so far: <n> cm. At the end print steps: <n> and total: <n> cm. Use the values given; do not type the answers.

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

far = 32
step = 7

The hint students can ask for: Keep a running total of how far you have driven and loop while it is less than the target. Each step is the step size, or whatever is left if that is smaller. Count the steps as you go.

A solution

from bugbot import *
connect()
far = 32
step = 7
done = 0
count = 0
while done < far:
    this = min(step, far - done)
    forward(50, distance=this)
    done = done + this
    count = count + 1
    print(f"so far: {done} cm")
print("steps:", count)
print(f"total: {done} cm")

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.