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

One question, two roads

Week 2 · 1.2 Selection in pseudocode · 3 lessons
1

True or false?

Computing 8: Topic 1.2, pp. 27–58
GoalWrite conditions with comparison operators and decide whether they are true or false.
New words
condition · a test that can only be true or falsecomparison operator · a symbol that compares two values: =, !=, <, >, <= or >=selection · a place in an algorithm where one set of steps or another is chosen, depending on a conditionBoolean value · one of only two values: true or false
Explanation

Selection means the program chooses between steps. It chooses by testing a condition. A condition compares two values with a comparison operator, and the answer is always true or false. In pseudocode the six operators are =, !=, <, >, <= and >=. Here a single = means ‘is equal to’, because assignment is written with the arrow. Words must be turned into the right operator. ‘At least 8’ includes 8, so it is >= 8. ‘More than 8’ does not include 8, so it is > 8. In a flowchart, the condition is written in a diamond, and one arrow leaves it for yes and one for no.

OperatorMeansExampleAnswer
=is equal to6 = 6true
!=is not equal to6 != 6false
<is less than4 < 9true
>is greater than4 > 9false
<=is less than or equal to5 <= 5true
>=is greater than or equal to4 >= 5false
Worked examples
In wordsCondition
the stall has more than 5 applesapples > 5
the stall has at least 5 applesapples >= 5
the bag holds exactly 5 applesapples = 5
the bag does not hold 5 applesapples != 5
there are no more than 5 applesapples <= 5
Everyday words become conditions. Look for the words that tell you whether the number itself counts.
StartINPUT hourhour >= 18?yesnoOUTPUT "Lights on"OUTPUT "Lights off"End
A bike light flowchart tests one condition. With 18 typed, hour >= 18 is true, so Lights on is shown. With 17 typed it is false, so Lights off is shown.
ConditionValues put inAnswer
apples > 56 > 5true
apples = 56 = 5false
price != 44 != 4false
price <= 44 <= 4true
name = "ali""Ali" = "ali"false
Conditions can use variables. Suppose apples holds 6, price holds 4 and name holds the string Ali. Work out each answer by replacing the names with the values. Strings are compared letter for letter, so Ali and ali are not equal.
Class activity

Human true or false (no computer). Make six number cards from paper (for example 3, 7, 10, 12, 15 and 20) and four condition cards: n < 10, n >= 12, n != 7, n = 15. Turn over one number card and one condition card. Replace n with the number and call out true or false. Your partner checks. Score a point for each right answer. Then write two condition cards of your own, for example n > 5 and n <= 10, and play again. If you have a computer or tablet, ask an adult to show you how Python prints True or False for a comparison.

Practice
1
Write a condition for each sentence. (a) The child is under 13 (variable age). (b) The basket has at least 8 eggs (variable eggs). (c) The card is not red (variable colour). (d) The player has scored exactly 3 (variable goals).
2
Here a is 7, b is 7 and c is 12. Is each condition true or false?
ConditionTrue or false?
a = b?
c < a?
c - a >= 5?
a != b + 1?
3
Trace the flowchart with the inputs 15, 9 and 22. What is shown each time?
StartINPUT temptemp < 15?yesnoOUTPUT "Wear a coat"OUTPUT "No coat needed"End
4
A pupil writes players < 6 for ‘no more than 6 players’. Test the condition with 6 players and say what is wrong. Write the correct condition.