Logic and computer systems · GCSE · OCR J277 2.4.1, AQA 8525 3.4.2, Edexcel 1CP2 1.3.1 · about 15 min
AND, OR and NOT, their symbols and truth tables, and a robot decision as a circuit.
[1 mark]When does an AND gate output 1?
[1 mark]When does an OR gate output 0?
[1 mark]How many rows does a truth table for 3 inputs have?
[1 mark]A is 1 and B is 1. What is A AND (NOT B)?
[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)))
1 0
NOT 0 is 1, so AND(1, 1) is 1; AND(1, 1) is 1, so NOT gives 0.
[1 mark]Which gate has only one input?
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 0The hint students can ask for: Two nested loops give you every combination of the two inputs. Work Q out from your gate functions rather than writing the answers down.
from bugbot import *
connect()
def AND(a, b):
return 1 if a == 1 and b == 1 else 0
def OR(a, b):
return 1 if a == 1 or b == 1 else 0
def NOT(a):
return 1 - a
for a in [0, 1]:
for b in [0, 1]:
print(f"A={a} B={b} Q={AND(a, NOT(b))}")
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.