The answersDownload the PDF
Worksheet

F9.1 Logic gates and truth tables

Logic and computer systems · GCSE · OCR J277 2.4.1, AQA 8525 3.4.2, Edexcel 1CP2 1.3.1 · about 15 min

BugBotLab
NameClassDate

What this lesson is about

AND, OR and NOT, their symbols and truth tables, and a robot decision as a circuit.

Questions 6 marks in all

  1. [1 mark]When does an AND gate output 1?

    1. AOnly when both inputs are 1
    2. BWhen at least one input is 1
    3. CWhen the inputs are different
    4. DWhen both inputs are 0
  2. [1 mark]When does an OR gate output 0?

    1. AOnly when both inputs are 0
    2. BWhen at least one input is 0
    3. CWhen the inputs are different
    4. DNever
  3. [1 mark]How many rows does a truth table for 3 inputs have?

  4. [1 mark]A is 1 and B is 1. What is A AND (NOT B)?

  5. [1 mark]What does this program print?

    def AND(a, b): return 1 if a and b else 0
    def NOT(a): return 1 - a
    print(AND(1, NOT(0)), NOT(AND(1, 1)))
  6. [1 mark]Which gate has only one input?

    1. ANOT
    2. BAND
    3. COR
    4. DXOR

The task: truth tables

Write AND(a, b), OR(a, b) and NOT(a) as functions that take and return 0 or 1. Print the truth table for A AND (NOT B), one row per line in the form A=0 B=1 Q=0, trying every combination with loops.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

def AND(a, b):
    return 0

Plan your program here, then type it in and press Run.

QR code
Do it on the robot
www.bugbotlab.com/learn/f9-1-logic-gates-and-truth-tables/
The simulator checks it and tells you when it passes. Nothing to install, no account.

Challenges

  1. Print the truth table for NOT (A OR B). Which gate does it match the opposite of?
  2. Make the robot's circuit also require that it has not just bumped into something, using bumped().
  3. How many rows does a truth table for 5 inputs have? Check by printing it.