GCSE · Computer Science · Eduqas · Spec C500QS

Mathematical and logical operations in code

Quick bet: what does Python 3 say 6 / 2 is? If you said 3, brace yourself. It says 3.0, and that is only the first surprise.

Computer Science · Operators

Be the interpreter: call every value

Eleven lines of Python. For each marked line, decide what the variable will hold before the page shows you.

Nothing is run here: every value is the lesson's. Step on with Next, and call each marked line before the page reveals it.

total = 17
groups = total // 5
left = total % 5
average = 7 / 2
ratio = 6 / 2
answer = 2 + 3 * 4
bracketed = (2 + 3) * 4
score = 50
passed = score >= 50
above = score > 50
result = passed and not above

Variables

total=17

Step 1. total holds 17. This first line is worked for you. From here on, you call each value before it appears.

Step 1 of 11Called right: 0 of 9

Computer Science · Choosing the operator

Which operator does the job?

Each line is something a program needs to work out. Pick the operator that does the job, then read why.

Still to sort

/ (true division) (0)

The exact value, decimal part kept

Where the line is: Use it when a decimal answer is fine. / always returns a float.

// (whole-number part) (0)

How many whole times it fits

Where the line is: Use it when the answer must be a whole number and the remainder is discarded.

% (remainder) (0)

What is left over

Where the line is: Use it for leftovers, and for testing whether a number divides exactly.

A comparison (==, >, <=...) (0)

A True or False answer about two values

Where the line is: Comparisons give True or False, never a number.

and / or / not (0)

Joining or flipping whole conditions

Where the line is: Use these when a rule needs more than one condition, or the opposite of one.

8 of 8 still to sort.

Computer Science · // and % together

Minutes into hours and minutes

Worked first: 200 minutes is 200 // 60 = 3 hours and 200 % 60 = 20 minutes, and 3 * 60 + 20 = 200. Now you finish the same method for 135 minutes.

  1. total = 135The total number of minutes is the starting point.
  2. missing step
Which line is step 2?

Computer Science · Order of evaluation

What does Python do first?

the order Python works through the parts of n % 3 == 0 or not n > 10 and n < 20

1 · Done first5 · Done last
  1. or

  2. not

  3. The arithmetic, n % 3

  4. and

  5. The comparisons ==, > and <

Computer Science · Checking working

Find the slip

A student worked out these lines by hand. One line is wrong, and the lines after it inherit the mistake. Which line is the first wrong one?

A student's hand-evaluation — which line goes wrong?

Computer Science · Short-answer practice

Write it, then mark it

(a) Explain the difference between = and == in Python. (b) Write a condition that is True for ages 13 to 19 inclusive, using age. [5 marks]

0 words · your answer stays on this page and is not sent anywhere.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Be the interpreter: work out what each line really gives, one operator at a time.

What you need to know

  • An expression combines values, variables and operators, and evaluating it always gives a single result.
  • Python 3's arithmetic operators are +, -, *, / (division), // (integer division), % (modulus, the remainder) and ** (power).
  • The / operator always returns a float, even when the division is exact: 7 / 2 is 3.5 and 6 / 2 is 3.0.
  • Have a goA classmate swears 10 / 5 'obviously' gives 2, because it divides exactly. Be kind, but correct them: what does Python 3 give?

    2.0 (a float)

    / always returns a float, even when the division is exact, so an exact answer still carries the .0.

  • // keeps the whole-number part, so 17 // 5 is 3. % keeps the remainder, so 17 % 5 is 2.
  • // rounds down towards negative infinity, so -7 // 2 is -4, not -3.
  • Have a goPredict before you look: what is -9 // 2? Think about which way is down.

    -5

    -9 / 2 is -4.5, and // rounds down towards negative infinity, so it lands on -5, not -4.

  • // and % work as a pair: 17 = 3 * 5 + 2, which is how total // 60 and total % 60 turn minutes into hours and minutes.
  • Arithmetic order: ** first, then * / // % left to right, then + and -. Brackets go before all of it.
  • Have a goWork out 10 - 2 * 3 and (10 - 2) * 3. Which one is bigger?

    (10 - 2) * 3 is 24; 10 - 2 * 3 is 4

    The multiplication happens before the subtraction by default; the brackets force the subtraction first.

  • Comparisons (==, !=, <, >, <=, >=) give True or False, and the boundary matters: at 50, score >= 50 is True but score > 50 is False.
  • = assigns a value; == compares two values for equality. Writing = where a comparison is intended is an error.
  • and needs both conditions True, or needs at least one, and not reverses a result. Each side must be complete: x == 1 or x == 2.

The big picture

An expression is built from values, variables and operators, and always boils down to one value. Python's own rules decide that value: / returns a float, // floors, % gives the remainder, precedence and brackets set the order, comparisons give True or False, and and / or / not combine complete conditions.

Key points

1An expression always evaluates to a single result.
2/ returns a float, // rounds down towards negative infinity, % gives the remainder.
3Precedence: ** first, then * / // % left to right, then + and -; brackets go first.
4A comparison evaluates to True or False; choose >= or > by the boundary value.
5= assigns, == compares.
6In a compound condition: arithmetic, then comparisons, then not, then and, then or.
7Each side of and / or must be a complete condition.

Worked example

Problem

age holds 65. Work out the value of age >= 13 and age <= 19 or age == 65

⚠ Watch out

Reading code like English or like a calculator: expecting 6 / 2 to be 3, -7 // 2 to be -3, = to mean the same as ==, or x == 1 or 2 to test both values. Evaluate each operator by its own rule instead.

🧠

Memory hook

Be the interpreter: one operator at a time, in Python's order, and commit to a value before you check it.

✓

Check yourself

Without running anything, work out 14 / 7, 14 // 4, 14 % 4 and 3 + 4 * 2. Then check: 2.0, 3, 2 and 11.

Flashcards

(15)
What does evaluating an expression give you?
A single result. Operators act on values and variables to form an expression, and the expression boils down to one value.
Name the seven Python 3 arithmetic operators.
+ addition, - subtraction, * multiplication, / division, // integer (whole-number) division, % modulus (remainder), ** exponentiation (power).
What does / give in Python 3, even when the division is exact?
A float. 7 / 2 is 3.5 and 6 / 2 is 3.0.
What does // give?
The whole-number part of a division; the remainder is discarded. 17 // 5 is 3.
What does // do with a negative result?
It rounds down towards negative infinity, so -7 // 2 is -4, not -3.
What does % give?
The remainder after whole-number division. 17 % 5 is 2.
How do // and % rebuild a number?
For positive whole numbers, a == (a // b) * b + (a % b). For example 17 = 3 * 5 + 2.
How do you test whether n is exactly divisible by k?
n % k == 0. For k = 2 it tests whether n is even.
In what order does Python 3 evaluate arithmetic?
** first, then *, /, // and % left to right, then + and - left to right. Brackets go first of all.
What does a comparison evaluate to?
True or False. The operators are ==, !=, <, >, <= and >=. Arithmetic is worked out before the comparison, so total % 3 == 0 works.
What is the difference between = and ==?
= is assignment. == compares two values for equality. Writing = where a comparison is intended is an error.
Why does the boundary value matter when you choose a comparison?
score >= 50 is True when score is 50, but score > 50 is False. Choose the comparison that matches the rule at the edge.
What do and, or and not do?
and is True only when both conditions are True. or is True when at least one is True. not reverses True and False.
In what order are the parts of a compound condition evaluated?
Arithmetic, then comparisons, then not, then and, then or. So a or b and c means a or (b and c); use brackets to show the grouping you intend.
What is wrong with x == 1 or 2?
It does not test whether x equals 2: each side of and/or must be a complete condition. Write x == 1 or x == 2.

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 Eduqas GCSE Computer Science topics

See the full Eduqas Computer Science curriculum →

How this lesson was checked. This Eduqas GCSE Computer Science (specification C500QS)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 16 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.