Turning a worded rule into AND, OR and NOT

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

Turning a worded rule into AND, OR and NOT

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Rule: "You can enter if you are both over 12 and have a ticket." Which condition matches?
A age > 12 AND hasTicket = TRUE
B age > 12 OR hasTicket = TRUE
2. Rule: "A student gets a lunch pass if they are in Year 9 or Year 10." Which condition matches?
A year = 9 OR year = 10
B year = 9 AND year = 10
3. Rule: "Allow the login unless the password is empty." Which condition matches?
A NOT (password = "")
B password = "" AND allowed
4. Rule: "The score must be between 50 and 80 (inclusive)." Which condition matches?
A score >= 50 OR score <= 80
B score >= 50 AND score <= 80
5. Rule: "The pool is closed if it is either raining or the temperature is below 15." Which condition matches?
A raining = TRUE AND temp < 15
B raining = TRUE OR temp < 15

Match the Pairs

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

Left columnRight column
1age >= 13 AND hasPermission = TRUE AThe rule 'between 13 and 19' means both limits must hold, so it needs AND, not OR. Also the comparisons are reversed, as this tests for outside the range.
2day = "Sat" OR day = "Sun" BThe rule says 'either': it is a weekend if the day is Saturday or Sunday, so one part being true is enough.
3'Unless the bag is empty, pack it' uses the key word 'unless', which signals NOT. CIF score >= 10 AND score <= 20 THEN
4'Between 10 and 20 inclusive' needs a lower limit AND an upper limit joined together. D'Either red or blue' signals OR, but AND was used. One variable cannot be both red and blue at once, so the condition is never true.
5IF age < 13 OR age > 19 THEN // rule: between 13 and 19 EThe rule says 'both': a student must be 13 or older and also have permission, so both parts must be true.
6IF colour = "red" AND colour = "blue" THEN // rule: either red or blue FIF NOT (bagEmpty = TRUE) THEN

Definitions

both = AND, either = OR, not = NOT

Fill in the Blanks

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

1.
// Rule: both marks are 50 or more IF maths >= 50 ___ english >= 50 THEN
2.
// Rule: either Saturday or Sunday IF day = "Sat" __ day = "Sun" THEN
3.
// Rule: unless it is raining IF ___ raining THEN
4.
// Rule: between 10 and 20 inclusive IF age >= 10 AND age __ 20 THEN
5.
// Rule: neither red nor blue IF NOT (colour = "red" __ colour = "blue") THEN

Spot the Error

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

Question 1
A INPUT age, ok
B IF age >= 13 OR ok = 1 THEN
C OUTPUT "Enter"
D ENDIF
Question 2
A INPUT cost
B INPUT vip
C ship ← 8
D IF cost > 50 AND vip = 1 THEN
E ship ← 0
F ENDIF
Question 3
A INPUT raining
B IF raining = 1 THEN
C OUTPUT "Go outside"
D ENDIF
Question 4
A INPUT m, a
B pass ← 0
C IF m < 50 OR a < 50 THEN
D pass ← 1
E ENDIF
Question 5
A INPUT n
B teen ← 0
C IF n >= 13 OR n <= 19 THEN
D teen ← 1
E ENDIF

Answer Key

Turning a worded rule into AND, OR and NOT
Section A: Quick Questions
Q1
A — age > 12 AND hasTicket = TRUE
Q2
A — year = 9 OR year = 10
Q3
A — NOT (password = "")
Q4
B — score >= 50 AND score <= 80
Q5
B — raining = TRUE OR temp < 15
Section B: Match the Pairs
Q1
age >= 13 AND hasPermission = TRUE → The rule says 'both': a student must be 13 or older and also have permission, so both parts must be true.
Q2
day = "Sat" OR day = "Sun" → The rule says 'either': it is a weekend if the day is Saturday or Sunday, so one part being true is enough.
Q3
'Unless the bag is empty, pack it' uses the key word 'unless', which signals NOT. → IF NOT (bagEmpty = TRUE) THEN
Q4
'Between 10 and 20 inclusive' needs a lower limit AND an upper limit joined together. → IF score >= 10 AND score <= 20 THEN
Q5
IF age < 13 OR age > 19 THEN // rule: between 13 and 19 → The rule 'between 13 and 19' means both limits must hold, so it needs AND, not OR. Also the comparisons are reversed, as this tests for outside the range.
Q6
IF colour = "red" AND colour = "blue" THEN // rule: either red or blue → 'Either red or blue' signals OR, but AND was used. One variable cannot be both red and blue at once, so the condition is never true.
Section C: Definitions
Q1
both = AND, either = OR, not = NOT — Key words in a worded rule signal the operator: both/and means AND, either/or means OR, not/unless/except means NOT. Use them to rewrite the rule as a compound condition.
Section D: Fill in the Blanks
Q1
// Rule: both marks are 50 or more IF maths >= 50 AND english >= 50 THEN
Q2
// Rule: either Saturday or Sunday IF day = "Sat" OR day = "Sun" THEN
Q3
// Rule: unless it is raining IF NOT raining THEN
Q4
// Rule: between 10 and 20 inclusive IF age >= 10 AND age <= 20 THEN
Q5
// Rule: neither red nor blue IF NOT (colour = "red" OR colour = "blue") THEN
Section E: Spot the Error
Q1
B — The rule says BOTH the age condition and the pass condition must be true, so the operator must be AND. With OR, someone with a pass but under 13 would get in.
Q2
D — The rule says EITHER an order over $50 OR a VIP gets free shipping. Either/or means OR. With AND, a VIP with a small order would be charged.
Q3
B — The rule says go outside UNLESS it is raining. 'Unless' means NOT, so the condition must be IF NOT (raining = 1) THEN. The broken line does the opposite.
Q4
C — 'Neither maths nor art is below 50' means NOT (either is below 50). The condition needs NOT around the whole bracket: IF NOT (m < 50 OR a < 50) THEN. The broken line passes students who are below 50.
Q5
C — 'Between 13 and 19' means both limits must be true at once, so the two tests are joined with AND. With OR, every number passes.