Choose exam board for KS4 Computer Science (GCSE)
Choose exam board for KS4 English
Choose exam board for KS4 French
Choose exam board for KS4 Geography
Choose exam board for KS4 German
Choose exam board for KS4 History
Choose tier for KS4 Maths
Choose exam board for KS4 Music
Choose exam board for KS4 Physical education (GCSE)
Choose exam board for KS4 Religious education (GCSE)
Choose exam board for KS4 Spanish

Lesson details

Learning outcome

I can write a function that replicates the output of an XOR gate.

Key learning points

  1. A logic gate is a fundamental component of a digital circuit.
  2. A truth table shows all possible combinations of inputs and the output that a circuit will produce.
  3. An XOR logic gate is True when either input is True, but not both.
  4. Unlike AND, OR and NOT, Python does not have a built-in operator for XOR.

Keywords

  • Logic gate - an electronic component that carries out a logical operation

  • Truth table - a table showing the outputs for all possible combinations of inputs to a logic gate or logic circuit

  • XOR - a Boolean operation that outputs True if either, but not both, of the input values are True

Common misconception

Python has a built-in XOR operator in the same way that it has AND, OR and NOT.

Unlike AND, OR and NOT, Python does not have a built-in operator for XOR and instead must be designed as part of and program that uses it.

Teacher tip

XOR is like a light that can be changed by two different light switches. Explore how turning on one switch turns the light on, but when both are on it turns off.

Equipment

Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor

Licence

This content is © Oak National Academy Limited (2026), licensed on Open Government Licence version 3.0
except where otherwise stated. See Oak's terms & conditions
(Collection 2).

Lesson video

Loading...

Prior knowledge starter quiz

6 Questions

Q1.
What will be the output when this program is run?
1234567
num1 = 5 num2 = 10 if num1 < 6 and num2 > 8: print("That is True") else: print("That is False")
Code colour

Correct answer: That is True
That is False

Q2.
What will be the output when this program is run?
1234567
num1 = 5 num2 = 10 if num1 == 5 or num2 > 11: print("That is True") else: print("That is False")
Code colour

Correct answer: That is True
That is False

Q3.
Match the definition to the keyword.

Correct Answer:scope,the section of a program where a variable can be accessed and modified

the section of a program where a variable can be accessed and modified

Correct Answer:local variable,only defined and visible for use in specific parts of a program

only defined and visible for use in specific parts of a program

Correct Answer:global variable,accessible from all parts of a program

accessible from all parts of a program

Q4.
What will be the output when this program is run?
123456
def divide(a, b): answer = a / b return answer divide(8, 2) print(answer)
Code colour

answer
8, 2
Correct answer: an error message
4

Q5.
Which of the following are reasons why global variables should be avoided?

Correct answer: It is difficult to keep track of the value of a global variable.
A variable can be accessed anywhere in the program.
Correct answer: It makes testing harder as you can no longer test a function in isolation.
You can run out of meaningful variable names.

Q6.
passing is the process of passing data into a subroutine and can be used as an alternative to global variables.

Correct Answer: Parameter

4 Questions

Q1.
Which of the following are built-in operators in Python?

Correct answer: `not`
Correct answer: `and`
xor
Correct answer: `or`

Q2.
What will this code output?
1234
one = 4 == 4 two = 2 != 2 print(xor_function(one, two))
Code colour

Correct answer: True
False

Q3.
What will this code output?
1234
one = 4*2 == 32/4 two = 2 == 2 print(xor_function(one, two))
Code colour

True
Correct answer: False

Q4.
Which logic gate symbol is used to represent XOR?

An image in a quiz
An image in a quiz
Correct Answer: An image in a quiz
An image in a quiz
An image in a quiz

To help you plan your 10 computer science lesson on: Creating an XOR function, download all teaching resources for free and adapt to suit your pupils' needs...