Skip to the worksheet
Revision Library
Choose a subject

Boolean Logic - Worksheets, Questions and Revision

15 original exam-style questions - 11 pages of questions with a full mark scheme - free printable PDF.

Grades 1-9

This topic is chapter 2 of GCSE Computer Science Topic Workbook 2 and chapter 12 of GCSE Computer Science 10-Minute Tests.

Revision Library
revisionlibrary.co.uk
GCSE · OCR

2.4 Boolean Logic

OCR J277 · Calculators not allowed · about 75 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
The NOT operator inverts (reverses) the value of a single Boolean input A. Complete the truth table below for NOT A.
ANOT A
0
1
(Total for Question 1 is 2 marks)
2
The AND and OR operators combine two Boolean inputs, A and B, to produce a single output.
(a)Complete the truth table for the AND operator.
ABA AND B
00
01
10
11
(4)
(b)Complete the truth table for the OR operator.
ABA OR B
00
01
10
11
(4)
(Total for Question 2 is 8 marks)
3
A student sets A = 1 and B = 0.
(a)What is the value of A AND B?(1)
  • A) 0
  • B) 1
  • C) Cannot be determined
  • D) Both 0 and 1
(b)What is the value of A OR B?(1)
  • A) 0
  • B) 1
  • C) Cannot be determined
  • D) Both 0 and 1
(Total for Question 3 is 2 marks)
4
Consider the Boolean expression X = NOT A AND B, where A and B are single-bit inputs.
(a)Complete the truth table for X.
ABNOT AX
00
01
10
11
(4)
(b)State how many of the four input combinations of A and B give an output of X = 1.(1)
(Total for Question 4 is 5 marks)
5
A smart heating system has a temperature sensor that outputs tempLow = True when the room temperature is below 18C, a window sensor windowClosed = True when the window is shut, and a manual override switch override, which the user can set to True to force the heating on regardless of the other sensors.
(a)Write a Boolean expression for heatingOn that turns the heating on when the temperature is low AND the window is closed, or when the override switch is on.(2)
(b)State the value of heatingOn when tempLow = True, windowClosed = False and override = False.(1)
(Total for Question 5 is 3 marks)
6
Complete the truth table below for the expression Output = A AND (B OR C).
ABCB OR COutput
000
001
010
011
100
101
110
111
(Total for Question 6 is 4 marks)
7
A logic circuit has two inputs, P and Q. Input P is connected to the input of a NOT gate. The output of the NOT gate, together with input Q, are the two inputs to an AND gate. The output of the AND gate is X.
(a)Write the Boolean expression for X in terms of P and Q.(1)
(b)Complete the truth table for the circuit.
PQX
00
01
10
11
(4)
(c)State the input values of P and Q that produce X = 1.(1)
(Total for Question 7 is 6 marks)
8
A programmer wants to build a logic circuit that produces the output of the Boolean expression X = A OR NOT B, using two inputs A and B.
(a)State the two logic gates that are needed to build this circuit.(2)
(b)Describe how the two gates would be connected to produce the correct output X.(2)
(Total for Question 8 is 4 marks)
9
A login validation routine uses three variables: usernameLength (an integer), hasDigit (a Boolean, True if the password contains at least one digit) and hasSpecialChar (a Boolean, True if the password contains at least one special character such as ! or #). Using OCR Exam Reference Language, write an IF statement that outputs "Valid" if usernameLength is at least 8 AND both hasDigit and hasSpecialChar are True, and otherwise outputs "Invalid".
(Total for Question 9 is 4 marks)
10
Complete the truth table below for the expression Output = (A OR B) AND NOT C.
ABCA OR BNOT COutput
000
001
010
011
100
101
110
111
(Total for Question 10 is 4 marks)
11
A programmer is designing a form-validation routine for a website that collects a user's age (which must be an integer between 5 and 100 inclusive) and a consent Boolean (True if the user has ticked a consent box).

Explain how Boolean logic operators (AND, OR, NOT) could be used to validate this data, including at least one example of a condition that combines more than one operator.
(Total for Question 11 is 4 marks)
12
A program is written using OCR Exam Reference Language:

count = 0
total = 0
for i = 1 to 5
mark = int(input("Enter a mark"))
if mark ≥ 40 AND mark ≤ 100 then
total = total + mark
count = count + 1
endif
next i
if count > 0 then
    average = total / count
    print(average)
else
    print("No valid marks")
endif

The program is run with the five inputs, in order: 35, 72, 100, 45, 105.
(a)Complete a trace table for this program using the five inputs given.
imarkcondition true?totalcount
135
272
3100
445
5105
(5)
(b)State the value output by the program.(1)
(Total for Question 12 is 6 marks)
13
The truth table below shows the output of a Boolean expression using three inputs A, B and C.
ABCOutput
0000
0010
0100
0111
1000
1011
1101
1111
(a)Which expression produces this truth table?(1)
  • A) (A AND B) OR (B AND C) OR (A AND C)
  • B) A AND B AND C
  • C) A OR B OR C
  • D) NOT A AND B AND C
(b)Justify your answer using one row from the table.(1)
(Total for Question 13 is 2 marks)
14
A programmer wants an algorithm that repeatedly asks the user to input a PIN (a string) until the PIN entered is exactly 4 characters long AND every character in it is a digit. You may assume a function IsDigit(character) that returns True if the character passed to it is a digit and False otherwise. The length of a string is given by pin.length, and the character at a position is given by pin.substring(position, 1), where positions start at 0, so pin.substring(0, 1) is the first character.

Using OCR Exam Reference Language, write an algorithm that repeats the input process until a valid PIN is entered, then outputs "PIN accepted".
(Total for Question 14 is 6 marks)
15
Complete the truth table below for the expression Output = NOT A OR (B AND NOT C).
ABCNOT ANOT CB AND NOT COutput
000
001
010
011
100
101
110
111
(a)Complete the Output column of the table.(4)
(b)State the number of the eight input combinations for which the expression is False.(1)
(Total for Question 15 is 5 marks)
Mark scheme · 2.4 Boolean Logic

Question 1

  • NOT A = 1 when A = 0B1
  • NOT A = 0 when A = 1B1
  • Answer: A=0 -> NOT A=1; A=1 -> NOT A=0

Question 2

  • (a) Row 1 (0,0) -> 0B1
  • (a) Row 2 (0,1) -> 0B1
  • (a) Row 3 (1,0) -> 0B1
  • (a) Row 4 (1,1) -> 1B1
  • (a) Answer: 0, 0, 0, 1
  • (b) Row 1 (0,0) -> 0B1
  • (b) Row 2 (0,1) -> 1B1
  • (b) Row 3 (1,0) -> 1B1
  • (b) Row 4 (1,1) -> 1B1
  • (b) Answer: 0, 1, 1, 1

Question 3

  • (a) A) 0 selectedB1
  • (a) Answer: A) 0
  • (b) B) 1 selectedB1
  • (b) Answer: B) 1

Question 4

  • (a) Row (0,0): NOT A=1, X=0B1
  • (a) Row (0,1): NOT A=1, X=1B1
  • (a) Row (1,0): NOT A=0, X=0B1
  • (a) Row (1,1): NOT A=0, X=0B1
  • (a) Answer: X values in row order: 0, 1, 0, 0
  • (b) 1, caoB1
  • (b) Answer: 1

Question 5

  • (a) tempLow AND windowClosed combined correctly, oeM1
  • (a) Full expression: heatingOn = (tempLow AND windowClosed) OR override, oe, brackets not requiredA1
  • (a) Answer: heatingOn = (tempLow AND windowClosed) OR override
  • (b) False (heating off), cao, ft from part (a) expressionB1
  • (b) Answer: False (heating stays off)

Question 6

  • Correct Output for rows 1-2 (A=0): 0, 0B1
  • Correct Output for rows 3-4 (A=0): 0, 0B1
  • Correct Output for rows 5-6 (A=1): 0, 1B1
  • Correct Output for rows 7-8 (A=1): 1, 1B1
  • Answer: Output column in row order: 0, 0, 0, 0, 0, 1, 1, 1

Question 7

  • (a) X = NOT P AND Q, oeB1
  • (a) Answer: X = NOT P AND Q
  • (b) Row (0,0) -> 0B1
  • (b) Row (0,1) -> 1B1
  • (b) Row (1,0) -> 0B1
  • (b) Row (1,1) -> 0B1
  • (b) Answer: X values in row order: 0, 1, 0, 0
  • (c) P=0 and Q=1, cao, ft from part (b)B1
  • (c) Answer: P = 0, Q = 1

Question 8

  • (a) NOT gate identifiedB1
  • (a) OR gate identifiedB1
  • (a) Answer: A NOT gate and an OR gate
  • (b) Input B is connected to the input of the NOT gateB1
  • (b) The output of the NOT gate and input A are connected to the two inputs of the OR gate, producing output XB1
  • (b) Answer: B feeds into the NOT gate; the NOT gate's output and A both feed into the OR gate, which outputs X.

Question 9

  • Correct relational operator used for length, e.g. usernameLength ≥ 8M1
  • All three conditions correctly combined using ANDM1
  • then branch outputs "Valid"M1
  • else branch outputs "Invalid", with endif used to close the statement; any correct logic, ignore minor syntax errorsM1
  • Answer:if usernameLength ≥ 8 AND hasDigit == True AND hasSpecialChar == True then
        print("Valid")
    else
        print("Invalid")
    endif

Question 10

  • Correct Output for rows 1-2: 0, 0B1
  • Correct Output for rows 3-4: 1, 0B1
  • Correct Output for rows 5-6: 1, 0B1
  • Correct Output for rows 7-8: 1, 0B1
  • Answer: Output column in row order: 0, 0, 1, 0, 1, 0, 1, 0

Question 11

  • Level 1 Basic or partial explanation of how a single Boolean operator could be used in validation. Little or no reference to combining conditions, or an example given without explanation.1-2
  • Level 2 Clear explanation of how AND, OR and/or NOT can be combined to validate both fields, supported by at least one correctly constructed combined condition (e.g. using AND to require the age to be in range and consent to be given).3-4
  • Indicative content:
    • AND can be used to require the age to be within range AND consent to be True at the same time, e.g. age >= 5 AND age <= 100 AND consent == True.
    • The two boundary checks (age >= 5 and age <= 100) must both be True, which is exactly what AND tests for.
    • OR could be used if there were multiple acceptable ways to satisfy a rule, e.g. accepting the record if consent == True OR an adult override flag is set.
    • NOT could be used to invert a check, e.g. NOT consent to flag records where consent has not been given.
    • A single combined condition reduces the need for multiple nested IF statements and makes the validation clearer and more efficient.

Question 12

  • (a) i=1, mark=35: condition False, total=0, count=0B1
  • (a) i=2, mark=72: condition True, total=72, count=1B1
  • (a) i=3, mark=100: condition True, total=172, count=2B1
  • (a) i=4, mark=45: condition True, total=217, count=3B1
  • (a) i=5, mark=105: condition False, total=217, count=3B1
  • (a) Answer: Final values after the loop: total=217, count=3
  • (b) average = 217/3, awrt 72.3, ft from part (a) totalsB1
  • (b) Answer: awrt 72.3 (217/3 = 72.333...)

Question 13

  • (a) A) selected, caoB1
  • (a) Answer: A
  • (b) A valid row used correctly to support the choice, e.g. row A=1,B=1,C=0 gives Output=1 because A AND B = 1, matching option A but not options B, C or DB1
  • (b) Answer: e.g. row A=1, B=1, C=0 gives Output=1; in option A, A AND B=1 so the expression is 1, matching the table. Option B needs all three inputs to be 1 so would give 0 here, so B is wrong.

Question 14

  • A loop structure is used that repeats the input process (e.g. do...until or while...endwhile)1 mark
  • The length of the entered PIN is correctly checked, e.g. pin.length == 4 (or ≠ 4 to flag invalid)1 mark
  • Iteration (e.g. for i = 0 to 3) is used with IsDigit correctly applied to check that every character is a digit2 marks
  • The length check and the digit check are correctly combined so that the loop only ends once both conditions are satisfied1 mark
  • print("PIN accepted") is produced once, after a valid PIN has been entered1 mark
  • Answer:do
    pin = input("Enter a 4-digit PIN")
    valid = True
    if pin.length ≠ 4 then
    valid = False
    else
    for i = 0 to 3
    if IsDigit(pin.substring(i, 1)) == False then
    valid = False
    endif
    next i
    endif
    until valid == True
    print("PIN accepted")

Question 15

  • (a) Rows 1-2 (A=0): Output=1, 1B1
  • (a) Rows 3-4 (A=0): Output=1, 1B1
  • (a) Rows 5-6 (A=1): Output=0, 0B1
  • (a) Rows 7-8 (A=1): Output=1, 0B1
  • (a) Answer: Output column in row order: 1, 1, 1, 1, 0, 0, 1, 0
  • (b) 3, cao, ft from part (a)B1
  • (b) Answer: 3

Mark your answers

Check answers without an account. Some answers can be checked automatically; use the mark scheme to mark the rest.

Question 1

2 marks
Did your answer earn the marks?

Question 2

8 marks
Did your answer earn the marks?

Question 3(a)

1 mark
Choose an answer

Question 3(b)

1 mark
Choose an answer

Question 4

5 marks
Did your answer earn the marks?

Question 5

3 marks
Did your answer earn the marks?

Question 6

4 marks
Did your answer earn the marks?

Question 7

6 marks
Did your answer earn the marks?

Question 8

4 marks
Did your answer earn the marks?

Question 9

4 marks
Did your answer earn the marks?

Question 10

4 marks
Did your answer earn the marks?

Question 11

4 marks
Did your answer earn the marks?

Question 12

6 marks
Did your answer earn the marks?

Question 13(a)

1 mark
Choose an answer

Question 13(b)

1 mark
Did your answer earn the marks?

Question 14

6 marks
Did your answer earn the marks?

Question 15

5 marks
Did your answer earn the marks?
Mark my answers

Worksheets are written for Revision Library and come with a full mark scheme; a few English packs quote an out-of-copyright text, and name it on the page. Exam board names and specification codes say which qualification a pack suits: we are not affiliated with, endorsed by or approved by any exam board, and no past-paper question is reproduced here. Rights queries: hello@revisionlibrary.co.uk