Logical operators AND, OR, NOT

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Logical operators AND, OR, NOT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which condition correctly checks that Age is between 0 and 120 inclusive?
A Age >= 0 OR Age <= 120
B Age >= 0 AND Age <= 120
2. Which condition is TRUE when Answer is outside the range 0 to 100?
A Answer < 0 OR Answer > 100
B Answer < 0 AND Answer > 100
3. Age is 25. What is the result of Age >= 0 AND Age <= 120?
A FALSE
B TRUE
4. Answer is 150. What is the result of Answer < 0 OR Answer > 100?
A TRUE
B FALSE
5. What does NOT do to a condition?
A It reverses TRUE to FALSE and FALSE to TRUE
B It makes both parts of the condition have to be true

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Age >= 0 AND Age <= 120 AReverses the condition: true when Score is anything except 50
2NOT (Score = 50) BAND is used where OR is needed. No number can be below 0 and above 100 at the same time, so the condition is never true. It should be Answer < 0 OR Answer > 100.
3OR is true when at least one condition is true, so it can catch a value outside a range C(Age < 13 OR Age > 19) AND Member = TRUE
4Brackets make clear which conditions are combined first in a complex condition DOR is used where AND is needed. Every number is at least 0 or at most 120, so invalid ages like -5 or 200 still pass. It should be Age >= 0 AND Age <= 120.
5IF Age >= 0 OR Age <= 120 THEN EAnswer < 0 OR Answer > 100
6IF Answer < 0 AND Answer > 100 THEN FTrue only when both conditions are true, so the age is inside the valid range 0 to 120

Definitions

AND OR NOT

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF Age >= 0 ___ Age <= 120 THEN OUTPUT "Age accepted" ENDIF
2.
IF Answer < 0 __ Answer > 100 THEN OUTPUT "Out of range" ENDIF
3.
IF ___ (Age >= 18) THEN OUTPUT "Under 18" ENDIF
4.
WHILE NOT (Answer >= 0 ___ Answer <= 100) DO INPUT Answer ENDWHILE
5.
Valid ← (Age >= 0) ___ (Age <= 120) OUTPUT Valid

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A INPUT Age
B IF Age >= 0 OR Age <= 120
C THEN
D OUTPUT "Valid"
E ENDIF
Question 2
A IF Answer < 0 AND Answer > 100
B THEN
C OUTPUT "Out of range"
D ENDIF
Question 3
A INPUT Age
B INPUT Paid
C IF Age >= 5 OR Paid = TRUE
D THEN
E OUTPUT "Enter"
F ENDIF
Question 4
A DECLARE Fail : BOOLEAN
B INPUT Mark
C Fail ← FALSE
D IF NOT (Mark < 50)
E THEN Fail ← TRUE
F ENDIF
Question 5
A DECLARE Age : INTEGER
B INPUT Age
C IF NOT Age < 0 OR Age > 120
D THEN
E OUTPUT "Accepted"
F ENDIF

Answer Key

Logical operators AND, OR, NOT
Section A: Quick Questions
Q1
B — Age >= 0 AND Age <= 120
Q2
A — Answer < 0 OR Answer > 100
Q3
B — TRUE
Q4
A — TRUE
Q5
A — It reverses TRUE to FALSE and FALSE to TRUE
Section B: Match the Pairs
Q1
Age >= 0 AND Age <= 120 → True only when both conditions are true, so the age is inside the valid range 0 to 120
Q2
NOT (Score = 50) → Reverses the condition: true when Score is anything except 50
Q3
OR is true when at least one condition is true, so it can catch a value outside a range → Answer < 0 OR Answer > 100
Q4
Brackets make clear which conditions are combined first in a complex condition → (Age < 13 OR Age > 19) AND Member = TRUE
Q5
IF Age >= 0 OR Age <= 120 THEN → OR is used where AND is needed. Every number is at least 0 or at most 120, so invalid ages like -5 or 200 still pass. It should be Age >= 0 AND Age <= 120.
Q6
IF Answer < 0 AND Answer > 100 THEN → AND is used where OR is needed. No number can be below 0 and above 100 at the same time, so the condition is never true. It should be Answer < 0 OR Answer > 100.
Section C: Definitions
Q1
AND OR NOT — Logical operators that combine BOOLEAN conditions: AND needs both true, OR needs at least one true, NOT reverses a condition. Use brackets in complex ones, e.g. Age >= 0 AND Age <= 120.
Section D: Fill in the Blanks
Q1
IF Age >= 0 AND Age <= 120 THEN OUTPUT "Age accepted" ENDIF
Q2
IF Answer < 0 OR Answer > 100 THEN OUTPUT "Out of range" ENDIF
Q3
IF NOT (Age >= 18) THEN OUTPUT "Under 18" ENDIF
Q4
WHILE NOT (Answer >= 0 AND Answer <= 100) DO INPUT Answer ENDWHILE
Q5
Valid ← (Age >= 0) AND (Age <= 120) OUTPUT Valid
Section E: Spot the Error
Q1
B — With OR, only one part has to be true, so every number passes (for example -5 is <= 120). A valid age must be >= 0 AND <= 120, so both parts must be true.
Q2
A — No number can be below 0 and above 100 at the same time, so AND is never true and bad answers are never caught. It should be OR, because only one part needs to be true.
Q3
C — Entry needs BOTH conditions to be true: old enough AND paid. With OR, someone aged 5 or over gets in without paying. It should use AND.
Q4
D — NOT reverses a condition. NOT (Mark < 50) is true when the mark is 50 or more, which is a pass, so Fail would be set wrongly. It should be NOT (Mark >= 50), which is true for marks below 50.
Q5
C — The brackets are missing, so NOT only reverses Age < 0 and the OR part is worked out separately. The whole condition needs brackets: NOT (Age < 0 OR Age > 120).