GCSE · Computer Science · OCR · Spec J277

Operators (arithmetic and Boolean)

17 / 5 gives 3.4. 17 // 5 gives 3. 17 % 5 gives 2. Same two numbers, three right answers. So which question is each operator asking?

Computer Science · Operators

Watch Python work it out

Six lines of Python. Step through them and watch each expression shrink, one rule at a time, until only a value is left.

Before you press Next: what number do you think ends up in result?

1 result = (2 + 3) * 4 ** 2 - 10 / 4
2 print(result)
3 exact = 17 / 5
4 whole = 17 // 5
5 left = 17 % 5
6 print(exact, whole, left)
expression nowresultexactwholeleft
(2 + 3) * 4 ** 2 - 10 / 4

Output

 

Step 1: Python can't swallow this in one go. It works through it in a fixed order. Which part do you think goes first?

1 / 10

The 'expression now' column isn't a variable. It shows the expression as it stands after each rule is applied.

Step 1 of 10: Python can't swallow this in one go. It works through it in a fixed order. Which part do you think goes first?.

Watch out: ** means 'to the power of'. 4 ** 2 is 4 × 4 = 16, not 4 × 2 = 8.

Predict, then check

Picture actually handing them out, one at a time.

You share 14 counters between 3 people. In Python, what do 14 // 3 and 14 % 3 give?

Computer Science · Kinds of expression

Number, or True/False?

Pick an expression, then choose the kind of expression it is.

Still to sort

Arithmetic: gives a number (0)

Built with arithmetic operators such as +, -, *, / and **. The result is a numeric value.

Where the line is: A number can sit inside a comparison, as in 3 * 4 > 10. Once there's a comparison, the final result is True or False, so it's no longer just arithmetic.

Relational: compares, gives True or False (0)

One comparison using ==, !=, <, <=, > or >=.

Where the line is: One comparison on its own is relational. Join comparisons with and or or, or put not in front, and it becomes logical.

Logical: combines comparisons (0)

Uses the operators and, or and not with relational expressions. Operators can be words, not just symbols. Still gives one True or False.

8 of 8 still to sort.

Eight expressions. The test for each one: what does it give back, and how many comparisons are in it?

Computer Science · Assignment or comparison?

One equals sign too few

This program should print the message only when age is 12. Which line doesn't do what was meant?

A classmate's program — which line goes wrong?

Computer Science · Conditions in selection

Which way does the program go?

Try three ages: 8, 35 and 72. Follow the route each one takes, and see where it ends up.

First comparison → Second comparison

3 possible routes.

On if age > 12 and age < 60:. 2 branches to choose from.

One condition, three possible ages. Each age takes exactly one route.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Python can divide two numbers three different ways. By the end you'll know which one you're asking for, and why one = sign is not the same as two.

What you need to know

  • An operator is a symbol or word that tells the computer to do a specific calculation or action.
  • Python's arithmetic operators: + add, - subtract, * multiply, / divide, ** to the power of. An arithmetic expression gives a number.
  • Order matters: brackets first, then indices (powers), then multiplication and division, and addition and subtraction last.
  • Have a goYour friend is certain 1 + 2 * 3 comes out as 9 in Python. Before you look: are they right?

    No. It's 7.

    Multiplication comes before addition, so 2 * 3 = 6 is done first, then 1 + 6. Your friend just went left to right.

  • Real division (/) divides the entire value, so there's no remainder: 9 / 2 is 4.5.
  • Integer division (also called floor division, // in Python) discards the remainder and leaves a whole number.
  • Modulo (MOD, written % in Python) gives you only the remainder.
  • Have a goQuick one: what's 20 // 6, and what's 20 % 6?

    3 and 2.

    6 goes into 20 three whole times (that's 18), so // gives 3. The 2 left over is what % gives. Mixing them up swaps the two answers.

  • Relational operators compare values and give True or False: == equal to, != not equal to, plus <, <=, > and >=.
  • Have a goTrue or False? First 7 != 7, then 7 <= 8.

    False, then True.

    != means 'not equal to', and 7 is equal to 7, so it's False. <= means 'less than or equal to', and 7 is less than 8, so it's True.

  • In Python, one = assigns a value; two == compares two values.
  • Logical operators and, or and not combine comparisons into one True or False: a logical expression.
  • Relational and logical expressions can be conditions in selection, deciding which way the program goes.

The big picture

An operator is a symbol or word that tells the computer to do a calculation or action. Arithmetic expressions (+, -, *, /, ** in Python) give a number, worked out in order: brackets, indices, multiplication and division, then addition and subtraction. / keeps the whole value, // throws the remainder away, and % (MOD) gives only the remainder. Relational operators compare values and give True or False; one = assigns, two == compares. Logical operators and, or and not combine comparisons, and these expressions act as conditions in selection.

Key points

1Operators are symbols or words that tell the computer to perform a calculation or action.
2Arithmetic expressions give a number and follow the order brackets, indices, multiplication and division, addition and subtraction.
3/ gives the full value, // gives the whole-number part with the remainder discarded, and % (MOD) gives only the remainder.
4Relational expressions compare values and give True or False; == compares, while a single = assigns.
5Logical expressions join comparisons with and, or and not, and they can be used as conditions in selection to control program flow.

Worked example

Problem

A game runs bonus = (7 + 5) // 5 + 2 ** 3 and then checks the condition bonus > 9 and bonus != 10. What is stored in bonus, and is the condition True or False?

⚠ Watch out

Writing = when you mean ==. A single = assigns, so it puts a value into a variable. To check whether two values are equal, as in a condition, you need the comparison operator ==.

🧠

Memory hook

One = puts a value in. Two == asks a question. And when dividing: / keeps it all, // keeps the whole part, % keeps the leftovers.

✓

Check yourself

Cover the page. Work out (6 + 2) ** 2 // 5, naming the rule you use at each step. Then explain why 64 % 5 and 64 // 5 give different answers.

Flashcards

(15)
What is an operator?
A symbol or word that instructs the computer to perform a specific calculation or action.
What does an arithmetic expression result in?
A numeric value.
What does ** do in Python?
Raises to a power ('to the power of'). For example, 3 ** 2 is 9.
Put these in the order Python works them out: addition and subtraction, brackets, multiplication and division, indices.
Brackets, indices, multiplication and division, then addition and subtraction.
Why does real division (/) never leave a remainder?
Because the entire value is divided. 15 / 2 is 7.5.
What happens to the remainder in integer (floor) division, and how is it written in Python?
It is discarded, leaving a whole number. Python writes it //, so 15 // 2 is 7.
What does modulo (MOD) return, and what is its Python symbol?
Only the remainder of a division. Python uses %, so 15 % 2 is 1.
What do relational operators do, and what does a relational expression evaluate to?
They compare values, and the expression evaluates to True or False.
What does != mean?
Not equal to. 5 != 6 is True; 5 != 5 is False.
What is the difference between = and == in Python?
= is assignment (it stores a value in a variable); == is the comparison operator (it checks whether two values are equal).
When is an and expression True?
Only when both relational expressions are True.
When is an or expression True?
When either or both relational expressions are True.
When is not True?
When the relational expression it works on is False.
What is a logical expression?
An expression that combines relational and logical operators, such as age > 12 and age < 60. It evaluates to True or False.
Where are relational and logical expressions used to control program flow?
As conditions in selection statements.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.