New
New
Year 10
AQA

Creating an XOR function

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

New
New
Year 10
AQA

Creating an XOR function

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

These resources will be removed by end of Summer Term 2025.

Switch to our new teaching resources now - designed by teachers and leading subject experts, and tested in classrooms.

These resources were created for remote use during the pandemic and are not designed for classroom teaching.

Lesson details

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

  • 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.


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

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.
Teacher tip

Equipment

Pupils need acces to software that allows them to write and run Python code. Links to examples in the Raspberry Pi Code Editor are provided as one such option.

Licence

This content is © Oak National Academy Limited (2025), 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

Download quiz pdf

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
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

Assessment exit quiz

Download quiz pdf

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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
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

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
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