Read it before you run it
A friend writes 10 - 4 / 2 and says the answer is 3. Is your friend right?
A good programmer can read code and say the answer before running it. This is the skill of interpreting code. It also helps you find bugs.
Key words
| Word | What it means | Example |
|---|---|---|
| Interpret | Read code and work out what it does. | say what 7 // 2 gives |
| Debug | Find and fix mistakes. | change = to == |
| Trace table | A table where you write each value after every step. | step, value |
| Operator | A symbol that does something to values. | + |
| Relational operator | An operator that compares two values. | >= |
| Boolean operator | And, or, not. They join True and False values. | a and b |
| Logic error | The program runs and gives a wrong answer. | > instead of >= |
The cells students fill in are left blank in this preview.
Is your friend right?
Have a go
Is your friend right?
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Worked example: trace an expression
| Step | What Python does | Value so far |
|---|---|---|
| Code | `result = 7 // 2 + 7 % 2 * 3` | |
| 1 | 7 // 2 is the whole part of 7 divided by 2 | 3 |
| 2 | 7 % 2 is the remainder | 1 |
| 3 | 1 * 3 (multiply before add) | 3 |
| 4 | 3 + 3 | 6 |
| Result | result is 6 | 6 |
The cells students fill in are left blank in this preview.
Try it: predict, then run
a = 7 // 2 + 7 % 2 * 3
b = (2 + 3) * 4 - 1
c = 5 > 3 and not 2 > 4
d = 17 % 5 == 2
print(a)
print(b)
print(c)
print(d)
# Write your predictions on paper first.
# Then run it and check.
Interpret the code
Have a go
Interpret the code
4 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.