GCSE · Computer Science · Edexcel · Spec 1CP2

Relational operators

Is a 12-year-old 'over 12'? You'd answer instantly. A program needs that question as an exact comparison with a True or False answer, and one missing symbol changes it.

Programming · Selection

One point, two different branches

Here's the same program run twice: first with a score of 10, then with 11. On each step, watch the highlighted line ask its question and get a True or False answer. (< means 'less than'; <= means 'less than or equal to'.)

Before you press Next: which line will print for a score of 10? And for 11?

1 score = int(input("Score: "))
2 if score < 0:
3 print("Negative")
4 elif score <= 10:
5 print("0 to 10")
6 else:
7 print("Over 10")

Variables

score=10

Output

 

Step 1: Run 1. Someone types 10, so score holds 10. Now the program starts asking questions: from the top, one at a time.

1 / 9

Step through both runs. Every True and False here is worked out for you in the notes, so check each one yourself before you read it.

Step 1 of 9: Run 1. Someone types 10, so score holds 10. Now the program starts asking questions: from the top, one at a time..

Exam line: To say which branch runs, evaluate each condition in order to True or False. The first True decides the branch.
Watch out: The else is reached only when every condition above it was False. As soon as one condition is True, everything below it is skipped.

Relational operators

Words into symbols

Pick a rule, then pick the operator that checks it.

Still to sort

== (0)

Where the line is: == is True only when the two values are exactly the same: 10 == 10 is True.

!= (0)

Where the line is: != is the opposite of ==. It's True whenever the two values are different, so 10 != 10 is False.

< (0)

Where the line is: < leaves the edge value out: 5 < 5 is False, because 5 isn't less than itself.

<= (0)

Where the line is: <= lets the edge value in: 5 <= 5 is True. Read it as 'at most'.

> (0)

Where the line is: > leaves the edge value out: 5 > 5 is False.

>= (0)

Where the line is: >= lets the edge value in: 5 >= 5 is True. Read it as 'at least'.

8 of 8 still to sort.

Programs can't read 'no more than 30'. Every rule has to be turned into a comparison between two values that comes out True or False. Match each rule to the one operator that checks it.

Watch out: 'Less than' and 'at most' sound alike, but they disagree about the edge: 30 < 30 is False, while 30 <= 30 is True.

Predict, then check

Read the condition out loud as a yes-or-no question before you choose.

A club's rule is: everyone aged 12 or over can join. The program checks if age > 12. A 12-year-old tries to join. What happens?

Spot the bug

One equals sign too few

This program should print Full marks! when score is 10. Python refuses to run it. Which line is wrong?

A student's program — which line goes wrong?

Your turn

Finish the working

number starts at 5. The program says: if number > 5, add 5 to number; else, subtract 5 from number. What value does number end with?

  1. The condition to check is number > 5, and number holds 5.
  2. missing step
Which line is step 2?

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Every if in a program asks a yes-or-no question. Relational operators are how it asks.

What you need to know

  • A relational operator compares two values and produces the result True or False.
  • The six relational operators are == (equal to), != (not equal to), < (less than), <= (less than or equal to, at most), > (greater than) and >= (greater than or equal to, at least).
  • An expression that uses a relational operator evaluates to True or False: age > 12 is False when age is 9 and True when age is 15.
  • In Python, == is used to compare two values and = is used to assign a value to a variable. Other languages may use different symbols for these jobs.
  • A condition is an expression that evaluates to True or False. Used with selection, it decides which code runs: if number > 5 the program adds 5 to number, otherwise (else) it subtracts 5.
  • In if / elif / else, the conditions are checked in order and the first one that evaluates to True decides the branch taken. If none is True, the else runs.

The big picture

A relational operator compares two values and gives back True or False. There are six: == (equal to), != (not equal to), < (less than), <= (at most), > (greater than) and >= (at least). A comparison such as age > 12 is a condition, and conditions drive selection: in an if / elif / else they're checked in order, and the first True one decides the branch. In Python, == compares while a single = assigns. The edge value is where > and >= disagree, so it's the value to test.

Key points

1Every comparison has exactly two possible results: True or False.
2Turn words into operators carefully: 'less than' is <, 'at most' is <=, 'more than' is >, 'at least' is >=.
3< and > leave the edge value out; <= and >= let it in. So 10 >= 10 is True, but 10 > 10 is False.
4Test for equality with ==. A single = stores a value in a variable.
5In if / elif / else, check from the top: the first True wins, and everything below it is skipped.
6Test a condition with the value right on its edge. That's where > and >= give different answers.

Worked example

Problem

A lift may only move when there are fewer than 8 people inside. The variable people holds how many are inside. Write the condition that allows the lift to move, then check it with 7 people and with 8 people.

⚠ Watch out

Picking > when the rule includes its edge. 'At least 50' means 50 counts, but score > 50 is False when score is 50, so a score of exactly 50 is wrongly turned away. Use score >= 50. The same slip happens with < and <= for 'at most'.

🧠

Memory hook

The little line under the symbol lets the edge in: <= and >= include the edge value, < and > shut it out. And one = stores, two == ask.

✓

Check yourself

x holds 7. Without looking back, say whether each is True or False: x != 7, x >= 7, x < 7. Then say which operator you'd use for 'at most 7'.

Flashcards

(11)
What does a relational operator do?
It compares two values and gives the result True or False.
Which operator tests whether two values are equal?
== (equal to).
Which operator means 'not equal to'?
!=
Which operator means 'less than'?
<. Anything below the edge value counts; the edge itself doesn't.
Which operator means 'at most'?
<= (less than or equal to). The edge value counts, and so does anything below it.
Which operator means 'more than'?
>. Anything above the edge value counts; the edge itself doesn't.
Which operator means 'at least'?
>= (greater than or equal to). The edge value counts, and so does anything above it.
In Python, what is the difference between = and ==?
= assigns a value to a variable. == compares two values and gives True or False.
What is a condition?
An expression that evaluates to True or False. Selection uses it to decide which code runs.
In if / elif / else, which branch runs?
The first one whose condition is True. If no condition is True, the else runs.
Which value should you always test a condition with?
The edge value, because that's where < and <=, or > and >=, give different answers.

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

See the full Edexcel Computer Science curriculum →

How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)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 29 September 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.