Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Read, write and fix code with operators

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

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

WordWhat it meansExample
InterpretRead code and work out what it does.say what 7 // 2 gives
DebugFind and fix mistakes.change = to ==
Trace tableA table where you write each value after every step.step, value
OperatorA symbol that does something to values.+
Relational operatorAn operator that compares two values.>=
Boolean operatorAnd, or, not. They join True and False values.a and b
Logic errorThe 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Worked example: trace an expression

StepWhat Python doesValue so far
Code`result = 7 // 2 + 7 % 2 * 3`
17 // 2 is the whole part of 7 divided by 23
27 % 2 is the remainder1
31 * 3 (multiply before add)3
43 + 36
Resultresult is 66

The cells students fill in are left blank in this preview.

Try it: predict, then run

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

8 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.