GCSE · Computer Science · Edexcel · Spec 1CP2

Relational operators

Is a 12-year-old 'over 12'? You'd answer instantly. A program has to ask an exact True-or-False question, and one tiny symbol decides the answer.

Programming · Selection

One point, two different branches

The same program, run twice: first with a score of 10, then with 11. Step through and watch each condition get its True or False answer in the state panel. (< 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? Commit to both, then step through.

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

Try to say each True or False yourself before the step shows 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. The moment 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.

A program can't read 'no more than 30'. Every rule has to become a comparison between two values that comes out True or False. Pick a rule, then 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?

Find 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 one of just two results: True or False.
  • age > 12 compares what's in age with 12. It's False when age is 9, and True when age is 15.
  • Have a goYour mate is completely sure that when age holds 15, age > 12 gives back 15. What does it really give back?

    True.

    A comparison never hands back one of its values. 15 is greater than 12, so the result is simply True.

  • == means equal to, and != means not equal to.
  • < is less than and > is greater than. Both leave the edge value out.
  • <= is less than or equal to (at most), and >= is greater than or equal to (at least). Both let the edge in.
  • Have a goNo pen needed: is 20 >= 20 True or False? And what about 20 > 20?

    20 >= 20 is True; 20 > 20 is False.

    A number is never greater than itself, so > leaves 20 out. >= also accepts 'equal', so 20 gets in.

  • So 10 == 10 and 10 >= 10 are True, 10 != 10 is False, 12 <= 13 is True, 5 > 10 is False.
  • In Python, == compares two values and a single = assigns a value. Other languages may use different symbols for these jobs.
  • Have a goTwo lines: lives = 3 and lives == 3. Which one puts 3 into lives, and which one asks a True or False question?

    lives = 3 puts 3 in; lives == 3 asks the question.

    It's tempting to read both as 'equals', but in Python one = assigns a value and two == compare two values.

  • A condition is an expression that's True or False. Selection uses it: if number > 5, add 5 to number; else, subtract 5.
  • In if / elif / else, conditions are checked in order. The first True one decides the branch; if none is True, the else runs.

The big picture

A relational operator compares two values and hands back True or False. There are six of them: == (equal to), != (not equal to), < (less than), <= (at most), > (greater than) and >= (at least). A comparison like age > 12 is a condition, and conditions steer selection: in an if / elif / else they're checked from the top, and the first True one picks the branch. In Python, == compares while a single = assigns. And the value sitting right on the edge is the one that catches mistakes, because that's where > and >= part ways.

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, work down from the top: the first True wins, and everything below it is skipped.
6Test a condition with the value sitting right on its edge. That's where > and >= disagree.

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 lets the lift move, then check it with 7 people and with 8 people.

⚠ Watch out

Grabbing > 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 gets 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 back 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 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 counts, and so does anything above it.
In Python, what's 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 none is True, the else runs.
Which value is the most useful one to test a condition with?
The value right on the edge. 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 26 October 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.