x

Revision notes for Edexcel GCSE Computer Science Arithmetic, relational and logical operators. Open the guide for explanations and worked examples. Written against the Edexcel GCSE Computer Science (1CP2) specification, so the content matches what's examinable rather than general Computer Science background.

Arithmetic, relational and logical operators

What you'll learn

  • How arithmetic operators calculate numeric values in algorithms.
  • How relational operators compare values and produce True or False.
  • How logical operators AND, OR and NOT combine conditions.
  • How to follow and write Python 3 conditions correctly for GCSE algorithms.

The basics: algorithms, values and expressions

An algorithm is a finite set of ordered steps used to solve a problem. In this topic, you are mainly looking at the small “working parts” inside those steps: calculations and decisions.

A value is a piece of data, such as 42, "hello" or True. A variable is a named storage location for a value, such as score or age.

Definition

Operator

An operator is a symbol or word that performs an action on one or more values. The values it works on are called operands. For example, in score + 10, the operator is + and the operands are score and 10.

An expression is a combination of values, variables and operators that produces a result. For example, score + bonus * 2 is an arithmetic expression because it calculates a number.

This overview shows how the three operator families fit together: arithmetic calculates numbers, relational comparisons produce Boolean values, and logical operators combine those Boolean values for decisions.

Summary diagram of arithmetic, relational and logical operators

Definition

Boolean

A Boolean is a data type with only two possible values: True or False. Relational and logical operators produce Boolean results.

Arithmetic operators

Arithmetic operators are used for calculations. They usually take numbers as input and produce a number as output.

Operator in Python 3NameMeaning
+additionAdd two values
-subtractionSubtract one value from another
*multiplicationMultiply two values
/divisionDivide and allow a decimal result
//integer divisionDivide and keep the whole-number quotient
%modulusFind the remainder after division
**exponentiationRaise to a power

Integer division and modulus

Two operators are especially important in algorithms:

  • // gives how many whole groups fit.
  • % gives what is left over.

For positive integers, if you divide 37 by 5, you can make 7 full groups with 2 left over. So 37 // 5 is 7, and 37 % 5 is 2.

Example

Splitting counters into full boxes

A program has 37 counters. Each box holds 5 counters. Work out how many full boxes can be made and how many counters are left over.

  1. Use integer division to find the number of full boxes: 37 // 5 gives 7, because 5 fits into 37 seven whole times.
  2. Use modulus to find the remainder: 37 % 5 gives 2, because after making 7 full boxes, 2 counters are left.
  3. Check the relationship: 37=7×5+237 = 7 \times 5 + 237=7×5+2, so the quotient and remainder make sense.
Tip

Remember // and % together

Think of // as “how many full groups?” and % as “what is left over?”

Order of operations

When an expression has several arithmetic operators, Python follows an order of operations:

  1. Brackets first.
  2. Exponentiation, such as **.
  3. Multiplication, division, integer division and modulus.
  4. Addition and subtraction.

Use brackets whenever they make your meaning clearer. This is especially useful in exams, because it reduces the chance of reading the expression incorrectly.

Example

Evaluating an arithmetic expression

Evaluate 3 + 4 * 2 ** 3.

  1. Apply exponentiation first: 2 ** 3 gives 8.
  2. Apply multiplication next: 4 * 8 gives 32.
  3. Apply addition last: 3 + 32 gives 35.
Common Mistake

Doing arithmetic strictly left to right

Do not evaluate 3 + 4 * 2 as if it were (3 + 4) * 2. Multiplication happens before addition unless brackets say otherwise.

Relational operators

Relational operators compare two values. The result is always a Boolean: True or False.

Operator in Python 3NameExample meaning
==equal toscore == 10 means score is equal to 10
<less thanage < 18 means age is less than 18
>greater thanheight > 150 means height is greater than 150
!=not equal tochoice != "Q" means choice is not Q
<=less than or equal tomark <= 100 means mark is at most 100
>=greater than or equal toscore >= pass_mark means score is at least the pass mark
Definition

Condition

A condition is an expression that evaluates to True or False. Conditions are used in selection, such as if, and iteration, such as while.

Example

Comparing a score with boundaries

Suppose score = 64, pass_mark = 50 and merit_mark = 70. Evaluate score >= pass_mark and score >= merit_mark.

  1. Compare the score with the pass mark: 64 >= 50 is True, because 64 is greater than 50.
  2. Compare the score with the merit mark: 64 >= 70 is False, because 64 is less than 70.
  3. Use the Boolean results in decisions: the student has passed, but has not reached the merit mark.
Common Mistake

Using = instead of ==

In Python, = assigns a value to a variable, such as score = 10. To test equality, use ==, such as score == 10.

Logical operators

Logical operators work with Boolean values. They are used to combine or invert conditions.

The three logical operators you need are:

  • AND: result is True only if both conditions are True.
  • OR: result is True if at least one condition is True.
  • NOT: reverses a Boolean value, so True becomes False and False becomes True.

In informal algorithms and exam explanations, you may see AND, OR and NOT. In Python 3 code, write them in lowercase as and, or and not.

Key Idea

Logical operators make decisions more precise

Relational operators create individual True or False tests. Logical operators combine those tests so an algorithm can make more detailed decisions.

Example

Combining conditions for access

A game lets a player start a level only if they have at least one life, at least 10 energy, and the game is not paused. Suppose lives = 2, energy = 8 and game_paused = False.

  1. Evaluate the first comparison: lives > 0 is True, because 2 is greater than 0.
  2. Evaluate the second comparison: energy >= 10 is False, because 8 is less than 10.
  3. Evaluate the NOT part: not game_paused is True, because game_paused is False.
  4. Combine using and: True and False and True gives False, so the player cannot start the level.
Common Mistake

Treating OR as exclusive

In GCSE Computer Science, OR is inclusive. This means A OR B is True when A is true, when B is true, or when both are true.

Writing algorithms with operators

When you write an algorithm, operators often appear inside assignment statements, if statements and loops.

For example:

  • total = price * quantity uses arithmetic.
  • if total >= 100: uses a relational operator.
  • if total >= 100 and member == True: combines conditions with a logical operator.

You can often make Boolean conditions neater. Instead of writing member == True, you can simply write member if member already stores a Boolean value. Instead of member == False, you can write not member.

Range checks

A range check tests whether a value is inside an allowed range. For example, to check whether age is between 11 and 16 inclusive, both comparisons must be true:

age >= 11 and age <= 16

You can also write this in Python as:

11 <= age <= 16

Both versions are valid Python, but the first version makes the two separate relational comparisons very clear.

Example

Writing a condition for a discount

A shop gives a discount if a customer buys at least 3 items and the total cost is greater than 20. Write the condition.

  1. Translate “at least 3 items” into a comparison: number_of_items >= 3.
  2. Translate “total cost is greater than 20” into a comparison: total_cost > 20.
  3. Both conditions must be true, so combine them with and: number_of_items >= 3 and total_cost > 20.

Following algorithms with mixed operators

In an exam, you may be asked to trace an algorithm. This means you carefully follow each line and keep track of variable values.

Consider this Python-style algorithm:

  • items = 14
  • boxes = items // 4
  • left_over = items % 4
  • order_complete = left_over == 0
  • needs_extra_box = boxes >= 3 and not order_complete
Example

Tracing mixed operators

Follow the algorithm and find the value of needs_extra_box.

  1. Calculate full boxes using integer division: 14 // 4 gives 3, so boxes becomes 3.
  2. Calculate the remainder using modulus: 14 % 4 gives 2, so left_over becomes 2.
  3. Compare the remainder with zero: left_over == 0 is 2 == 0, which is False, so order_complete becomes False.
  4. Evaluate the final logical expression: boxes >= 3 is True, and not order_complete is also True.
  5. Combine the two Boolean values: True and True gives True, so needs_extra_box is True.
Tip

Use brackets for readability

not, and and or have their own precedence rules, but you should use brackets to make complex conditions clear, such as (age >= 11 and age <= 16) and not is_banned.

Exam technique

In the exam

  1. Work out arithmetic expressions first, then relational comparisons, then logical combinations.
  2. Be precise with Python symbols: use == for equality, // for integer division, % for remainder, and lowercase and, or, not in code.
  3. When tracing, write down each new variable value and each Boolean result before combining conditions.
Self review

Check yourself

  • What are the results of 23 // 5 and 23 % 5, and what do they mean?
  • Why does score = 10 mean something different from score == 10 in Python?
  • For A OR B, which input combinations make the result True?
You've reached the end

Test yourself on this topic, or move on to the next guide.

FlashcardsSelf-test with active recall
Tracing algorithm output with trace tablesUp next

How was this guide?

Arithmetic, relational and logical operators Revision Guide

  1. GCSE
  2. /Computer Science
  3. /Arithmetic, relational and logical operators