Where marks are lost
The ten commonest mistakes, checking on paper, and repairing a broken program.
Do this lesson in the simulatorMost lost marks are not lost to ignorance. They are lost to answering a different question, to stopping halfway, or to a slip that two seconds of checking would have caught. This lesson is the list of those mistakes, and a broken program to repair against the clock.
The ten that cost the most
- Answering the wrong command word. A "describe" answered with one word; an "explain" with no because.
- One point repeated. Four marks need four different points.
- Leaving it blank. An empty answer is certainly nothing; a reasonable attempt often is not.
- Ignoring the situation. The question names a hospital or a farm; the answer talks about computers in general.
- Vague words. "It is better", "it is faster", "more efficient" with no because.
- Stopping the program halfway. Later parts often need nothing from the earlier ones: write them anyway.
- Using the wrong units, or none. Bits against bytes, kB against MB, a number on its own.
- Off-by-one. A loop that runs once too often, a list index at the end,
FOR 1 TO 5againstrange(1, 5). - Not reading the whole question. The last line often adds a condition, and the marks follow it.
- Running out of time. Long answers on a 1-mark question, then nothing written for an 8-mark one.
Checking a program on paper
You cannot run it in a written paper, so trace it (lesson F13.2) with:
- a normal value;
- the boundary: the first and last allowed;
- something invalid.
If all three do what the question asked, you have almost certainly got the marks.
The slips that break code
| Slip | What it looks like |
|---|---|
= instead of == |
a comparison that assigns |
| counter set inside the loop | it never grows past one |
< where <= was meant |
the last item is missed |
| the variable name spelled two ways | flashs and flashes |
| input not converted | "5" + 1 fails, "9" > "10" is true |
| the check after the action | validating a value you already used |
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# what the question asked for: the total of the numbers 1 to 5, and how many were odd
total = 0
odd = 0
for n in range(1, 6): # 1 TO 5 means range(1, 6)
total = total + n
if n % 2 == 1: # == compares; = would assign
odd = odd + 1
print("total:", total, "odd:", odd)
Task: repair the program
This program should drive 4 steps of 15 cm, printing step <n>: <total> cm after each one, then total: 60 cm and turn the LED green. It has three faults. Find them, fix them, and leave the rest alone.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
for step in range(1, 4):
total = 0
forward(50, distance=15)
total = total + 15
print(f"step {step}: {total} cm")
print(f"total: {total} cm")
led(255, 0, 0)
Challenges
- Which of the three faults would a trace table have caught first?
- Add a comment above each fix saying what was wrong.
- Pick two mistakes from the list of ten that you have made, and write how you will avoid each.