AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Two tests, one decision

Week 4 · 1.2 Selection in pseudocode · 3 lessons
1

Joining two conditions

Computing 8: Topic 1.2, pp. 27–58
GoalUse AND, OR and NOT in a condition and work out the result by replacing each condition with true or false.
New words
Boolean operator · AND, OR or NOT, used to combine or reverse conditionsAND · true only when both conditions are trueOR · true when at least one condition is true; false only when both are falseNOT · reverses a condition: true becomes false and false becomes true
Explanation

One condition is sometimes not enough. Boolean operators let a condition ask more than one question. With AND, both conditions must be true. With OR, one true condition is enough, and the result is false only when both are false. NOT goes in front of one condition and turns true into false and false into true. To work out a combined condition, first work out each small condition using the values in the variables. Then replace each one with True or False and apply the operator. Each side of AND or OR must be a complete condition, so we write wind >= 5 AND wind <= 20, not wind >= 5 AND <= 20.

ABA AND BA OR BNOT A
TrueTrueTrueTrueFalse
TrueFalseFalseTrueFalse
FalseTrueFalseTrueTrue
FalseFalseFalseFalseTrue
Worked examples
Pseudocode
1INPUT wind
2IF wind >= 5 AND wind <= 20 THEN
3    OUTPUT "Good for kites"
4ELSE
5    OUTPUT "Not today"
6ENDIF
Kite day. The wind must be at least 5 and at most 20. For wind = 12 the two conditions are True and True, so True AND True is True and the output is Good for kites. For wind = 21 they are True and False, so the AND is False and the output is Not today.
Pseudocode
1INPUT day
2IF day = "Sunday" OR day = "Holiday" THEN
3    OUTPUT "Library closed"
4ELSE
5    OUTPUT "Library open"
6ENDIF
A library is closed on Sundays and on holidays. OR needs only one true condition. On a Sunday the first condition is True, so True OR False is True. For Monday both conditions are False, so the result is False. The day is stored as a string, so it needs quotation marks.
Pseudocode
1INPUT seats
2IF NOT (seats = 0) THEN
3    OUTPUT "Seats left"
4ELSE
5    OUTPUT "Full"
6ENDIF
NOT reverses a condition. If seats holds 0, then seats = 0 is True and NOT True is False, so the output is Full. If seats holds 7, then seats = 0 is False and NOT False is True, so the output is Seats left.
Class activity

Rule cards (no computer). Write the numbers 1 to 12 on slips of paper and put them in a bag. Make three condition cards on paper: ‘n > 4 AND n < 9’, ‘n < 3 OR n > 10’ and ‘NOT (n = 6)’. Draw a number. For each card, write the True or False result of each small condition, then the final result. Keep a score sheet with the headings number, condition 1, condition 2, result. Draw eight numbers. Which card is true most often? If you have a computer or tablet, ask an adult to run a Python version to check your table.

Practice
1
The variable x holds 6. Work out each combined condition. Write True or False for each small condition first.
ConditionSmall conditionsResult
x > 3 AND x < 6??
x = 6 OR x = 7??
NOT (x = 6)??
2
Write a condition for each. (a) The child is 8 or older but younger than 13 (variable age). (b) It is Saturday or Sunday (variable day).
3
Follow the algorithm for the speeds 30, 31 and 0. What is shown each time?
Pseudocode
1INPUT speed
2IF speed >= 1 AND speed <= 30 THEN
3    OUTPUT "Allowed"
4ELSE
5    OUTPUT "Not allowed"
6ENDIF
4
When is the condition A OR B false? When is A AND B true? Answer in one sentence each.