0% found this document useful (0 votes)
32 views35 pages

G6 T3 Notes 0860

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views35 pages

G6 T3 Notes 0860

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Unit 8.

1 Algorithms and data

Learning objectives Suggested teaching activities and resources Additional notes


8CT.03 Identify the Display a sequence of steps that are presented in structured
important characteristics statements and ask learners to follow them, for example:
of pseudocode, including Stand up, take 2 steps back, clap your hands twice, sit on
that it should be short, the floor, lie down, stand up, jump 3 times.
clear and precise and Through class discussion, elicit that these are short statements
should have the start and that are precise. Also elicit that it is clear what they mean without
end clearly shown. the need to ask for further information.
8CT.01 Follow and
Display the word ‘pseudocode’ and define it as:
understand algorithms that
a way of planning the structure and function of a program
are presented as
in a short, clear and precise way.
pseudocode.
Also explain that pseudocode is not specific to any programming
language.

It is also important to emphasise that there is no defined


pseudocode that everyone uses. The pseudocode that is written
and used will differ depending upon an individual’s purpose and
experience. All pseudocode should, however, use the same
programming constructs and rules, such as assignment,
comparison and iteration.
Put learners into pairs and give each pair a selection of different The similarities may include:
pseudocode algorithms that perform the same function but are • using a symbol (= or ) for assignment
written differently. Ask them to read through and discuss each • using a command for reading in
example to identify the similarities between the different • the addition symbol
algorithms. The examples could include: • using a command word for outputting
• the use of variables to store data in.
INPUT value1
INPUT value2
OUTPUT value1 + value2
Learning objectives Suggested teaching activities and resources Additional notes

value1 = INPUT
value2 = INPUT
result = value1 + value2
print(result)

value1  ReadLineFromUser
value2  ReadLineFromUser
Printout value1 + value2

Now give each pair a list of constructs and ask them to identify a A valid pseudocode statement for ‘input’ could be
number of different ways that they can be written. For example, input, enter, read from user, type data,
ask the pairs to write pseudocode commands to either input or read line, read line from user.
output an item of data.
While all of these examples are valid pseudocode,
Ask the pairs for their answers and create a list of the valid Cambridge have created pseudocode guides in support
possibilities, identifying examples that would be appropriate in of the IGCSE, AS Levels and A levels in Computer
pseudocode because they clearly demonstrate that data is input Science. You can view these pseudocode guides on,
and because they are concise. and download them from, the Cambridge International
School Support Hub. Find them under the ‘teaching
Display a pseudocode algorithm and ask learners to follow it to and learning’ section for each of the Computer Science
identify the output for a given input. An example algorithm could syllabuses.
be:
INPUT name
INPUT favouriteColour
INPUT favouriteFood
OUTPUT "Hello ", name, " your favourite
food is ", favouriteFood, " and your
favourite colour is ", favouriteColour

Review learners’ understanding of pseudocode by asking them to


make personal notes about what they have learned. They can
present these notes in any format but the content should be
informed by their responses to the following questions:
Learning objectives Suggested teaching activities and resources Additional notes
• What is pseudocode?
Answer: A form of representing an algorithm without a
set syntax.
• When is pseudocode used?
Answer: When planning or designing algorithms.
• Why is pseudocode used?
Answer: It is language independent so anyone should be
able to understand it.
• What features does pseudocode contain?
Answer: Command words, assignment symbols,
mathematical symbols.

Resources:
• prepared sequences of steps that are presented as
structured statements
• prepared sequences presented as pseudocode.
8CT.02 Follow flowcharts Gather learners’ existing knowledge and understanding of
and pseudocode conditional statements by asking:
algorithms that use What is selection?
conditional statements. Elicit that selection is an instruction within an algorithm where a
decision is made about whether to run a piece of code or not.
Then ask:
How is selection usually written in programming?
Elicit that it is usually written as a question, or a comparison, that
results in ‘true’ or ‘false’.

Ask:
What are the key words used in conditional statements in
programming?
Answer: IF, THEN, ELSE
What are the different symbols that can be used for
comparisons?
Answer: >, <, >=, <=, <> = <> or != are both acceptable for not equal to.
Learning objectives Suggested teaching activities and resources Additional notes
= or == are both acceptable for equal to.
Put learners into pairs and give them a series of flowcharts that Learners should already be familiar with following
use conditional statements. For example: conditional statements in flowcharts but, if they are not,
begin with an introduction to the diamond selection
statement, and explain that it has ‘yes’ and ‘no’ arrows
which are followed depending on whether the response
to the question is true or false.

Learners may benefit from using algorithms that they


have developed or worked with in earlier stages, that
contain a decision, or IF statement. This will enable
them to understand these in the context of a flowchart.

Ask the pairs to follow the algorithms, with different input data,
and identify the outputs.
Display an example of pseudocode, to suit Python, for an IF This pseudocode is one way of presenting IF THEN
statement. For example: ELSE statements. There are other ways such as:
if condition: IF condition THEN
Code to run if true Code to run if true
else: ELSE
Code to run if false Code to run if false
Explain that this shows the IF command, followed by the ENDIF
condition, then a ‘:’. All of the code that follows the ‘if or
condition:’ is indented and only runs if the condition is true. If (condition)
Then
Also explain that the else: needs to be aligned with the IF, and Code to run if true
the code underneath is also indented, and that this is the code Else
that will run if the condition is false. Code to run if false
Learning objectives Suggested teaching activities and resources Additional notes
endif
Return learners to their pairs and give each pair a series of
pseudocode algorithms that make use of selection (IF, THEN,
ELSE) statements. Examples could include:
Input Value1
Input Value2
if Value1 >= Value2:
OUTPUT Value1
else:
OUTPUT Value2

Colour = INPUT("Do you prefer purple or


green?")
if Colour == "purple":
OUTPUT "Purple is the best"
else:
OUTPUT "Purple is better than green"

Ask the pairs to follow the algorithms, using different sets of data,
and to work out what they do. They should also identify the three
different parts of the condition statement in each program. These
are:
• the condition
• the code that is run when the condition is true
• the code that is run when the condition is false.

Hold a class discussion to consider the following questions:


What is the format of a pseudocode conditional
statement?
Answer: IF THEN ELSE, or if condition: else:
What are the three component parts of a conditional
statement?
Answer: the condition; the code to run if true; the code to
run if not true
Learning objectives Suggested teaching activities and resources Additional notes
Did you encounter any problems when following the
condition statements?
How did you know which code to run and which not to
run?
Did you try the algorithms with different data to see how
the code changed?

Resources:
• prepared flowcharts that include conditional statements
• prepared pseudocode that includes conditional
statements.
8CT.07 Predict the Put learners into pairs and give them a copy of a flowchart. Ask
outcome of algorithms and them to read the algorithm and its steps. An example flowchart
test that they meet those might be:
outcomes.

Provide two values for input, such as 4 and 2. Ask the pairs to
predict what the output will be without using the flowchart. Ask
them to then use the algorithm and check if their answer is
correct. They should predict that the output is 2. Repeat this with
different values.
Learning objectives Suggested teaching activities and resources Additional notes
Repeat this process with different algorithms in different formats, Example algorithms:
for example: Output a message depending on the age of the user:
• pseudocode age = input("Enter your age")
• written as a list of instructions if age < 18:
• an actual program. print("You are a child")
The algorithms could: else:
• output a message depending on the age of the user print("You are an adult")
• output a grade depending on the mark entered
Output a grade depending on the mark entered:
• represent a calculator
• represent a computer game where the character moves
and speaks different phrases depending on the input.

Give each learner in the pairs a different algorithm from each


other and a set of input data. Ask them to each predict the output
of their algorithm and then to swap with their partner. The partner
should test the algorithm, using the same input data, to check
whether the prediction was correct.

Display the following questions:


Were your predictions always correct?
If one was wrong, why was it wrong?
Did you make an incorrect prediction or was there a
problem with the algorithm? A calculator:
If there was a problem with the algorithm, were you able number1 = input("Enter the first number")
to identify what it was and correct it? number2 = input("Enter the second
Allow for a short period of reflection and then ask learners for number")
calculation = input("Enter the
their responses. Once three learners have spoken, ask if any
calculation")
others have different experiences from those already shared.
IF calculation == "+" THEN
Then ask a learner who has not spoken to say which of the
result = number1 + number2
responses they will consider when they make predictions or
ELSE
correct errors in algorithms in the future.
IF calculation == "-" THEN
result = number1 - number2
ELSE
Learning objectives Suggested teaching activities and resources Additional notes
IF calculation == "/" THEN
result = number1 / number2
ELSE
result = number1 * number2
ENDIF
ENDIF
ENDIF

A computer game where the character moves and


speaks different phrases depending on the input:

8CT.08 Know how to Display a description of an everyday task, for example:


decompose problems into • brushing teeth
their sub-problems. • making a hot drink
• making a pizza
• baking a cake.
Put learners into small groups and ask them to discuss the task
and to make a plan for how they will attempt to complete it. Ask
the groups to share their plan and, through a class discussion,
create a consensus that the task should be written in separate
sections. Support learners to understand that decomposing the
task into smaller pieces will mean that every part does not need
Learning objectives Suggested teaching activities and resources Additional notes
to be considered at the same time. For example, for baking the
cake, the task could be broken down as follows:
• obtain the ingredients
• mix the ingredients
• bake the ingredients.
Give the groups a scenario, for example: There is not necessarily a correct answer for how the
A shop wants to launch a new website. They task could be broken down, and each group is likely to
need to: take a different approach. For example, one group may
• create new artwork, such as a logo suggest splitting the website creation task into the
• include information such as structure and content, while another may split each
information about the shop. page individually. There is also no set order for the
The website also needs to include the facility separate parts because it is not an algorithm; therefore
for customers to purchase items online. the different parts of the task can be completed
simultaneously.
Explain that each group needs to share the task between each
member so that they all have a specific role. Ask the groups how
they divided the tasks between themselves.
Hold a class discussion to define decomposition as splitting a Learners will have understood decomposition from
task into its sub-problems. Also discuss the benefits of earlier stages but the idea that the sub-problems can
decomposition, including that: be divided between different people may be new to
• it is easier to solve many small problems than one large them.
problem
• if there are multiple people working on a problem, the task
can be divided between them. This means that:
o different parts of the task can be completed
simultaneously
o tasks can be designated according to specific skills or
specialities.

Now put learners into pairs. If possible, they should have the
opportunity to work with a partner that they haven’t yet worked
with during this activity.
Learning objectives Suggested teaching activities and resources Additional notes
Give each pair a description of a problem for which a computer
program needs to be written in order to solve it. The problems
should be fairly large so that the pairs can focus their discussion
on splitting the problem into sub-problems, rather than starting to
focus on how the program will actually work.

For example, you could give them the problem of a satellite


navigation system. A possible decomposition of a satellite
navigation system could be:
• storing the maps
• allowing the input of the destination
• finding the current location
• finding the route to the destination
• displaying the route
• outputting the directions.

Ask learners to create a mind map that enables them to capture


their understanding of decomposition. The content of the mind
maps should be informed by the learners’ responses to the
following questions:
What is decomposition?
Answer: Splitting a problem into smaller problems.
How does decomposition help you solve a problem?
Answer: Smaller problems are easier to solve and then
join together.
How does decomposition help a team build a program?
Answer: Tasks can be split between individual team
members.

Resources:
• prepared tasks, scenarios and problems for learners to
decompose.
Learning objectives Suggested teaching activities and resources Additional notes
8CT.09 Know how to Introduce this activity by displaying the word ‘constant’ and If you introduce constants using a text-based language,
develop algorithms that asking: note that Python does not support constants. In Python,
use at least one constant. What does this word mean? although a value can be intended as a constant, it is
Elicit that a constant is something that stays the same and cannot still possible to change it.
change.

Describe the example of a computer where:


• a player has a set number of points at the start
• they lose one of these points each time they are
successfully attacked by another player
• the game ends when all the points have been lost.
Put learners into pairs and ask them to discuss which values do This discussion activity could be linked to other
not change in this example. The pairs should identify: subjects. For example:
• the number of points that the player starts with • mathematics – where the value of Pi is constant
• the number of points that they lose each time they are • science – where the constant is the value that
successfully attacked Fahrenheit is multiplied by to get the temperature
• the number of points that indicates that the game ends – in Celsius.
0 points.
Explain that a constant in programming can be defined as It is important at this stage to differentiate between a
a space in memory that stores a value that cannot be value that does not change and a value that cannot
changed while the program is running. change. A value could be stored in a variable, and then
An example could be a program that uses a constant to always this stays the same throughout a program, but it is
initialise the number of points at the start of the game to 3. possible to actually change it; therefore it is not a
constant. A constant can only be changed if the
Also explain the purpose of constants, for example: program is stopped, the source code is altered and
• they prevent accidental changes, for example incorrectly then the program is run again.
adding extra points for a player at the start of the game
• if the value needs to be changed, it only needs to be done ‘Declaring’ a constant, or a variable, is required to
once and then it will change automatically throughout the create space in the memory for that constant, or for a
program. For example, if the number of points lost when variable.
the player is successfully attacked needs to be increased
to 2, the value of the constant only needs to be changed
once instead of every time the code for a successful
Learning objectives Suggested teaching activities and resources Additional notes
attack occurs. This reduces the risk of human error in the
coding and saves time.
Display an algorithm that uses values that might be constants, for OUTPUT 1 * 12 means OUTPUT 1 multiplied by 12.
example: Therefore, all the outputs are multiplied by the same
OUTPUT 1 * 12 number – 12.
OUTPUT 2 * 12
OUTPUT 3 * 12
OUTPUT 4 * 12
OUTPUT 5 * 12
Elicit that, in this example, the number 12 is the same for all five
outputs, so 12 is therefore the constant.

Explain that using 12 as a variable means that the value of the


multiplier can be changed, for example from 12 to 5, and will be
updated throughout the algorithm. For example
Constant multiplier = 12
OUTPUT 1 * multiplier
OUTPUT 2 * multiplier
OUTPUT 3 * multiplier
OUTPUT 4 * multiplier
OUTPUT 5 * multiplier
can easily be changed to:
Constant multiplier = 5
OUTPUT 1 * multiplier
OUTPUT 2 * multiplier
OUTPUT 3 * multiplier
OUTPUT 4 * multiplier
OUTPUT 5 * multiplier
Give pairs of learners a description of an algorithm. These might For the miles to kilometres example, an algorithm could
include: be:
• convert miles to kilometres Constant multiplier = 1.609
• convert pints to millilitres. Miles = INPUT("Enter a number of
miles")
OUTPUT Miles * multiplier
Learning objectives Suggested teaching activities and resources Additional notes
Ask the pairs to write an algorithm and then decide which value
or values should be a constant. The pairs should adapt their
algorithm to declare and then use the constant.

Ask the pairs to share their algorithms and to explain how they
identified, declared and used the constants. During these
discussions, check individual learner’s understanding of
constants by asking questions such as:
What is a constant?
Answer: A space in memory that stores a value that
cannot be changed while the program is running.
Why do you use a constant instead of a variable?
Answer: To avoid accidental changes. To allow you to
change the value once so it updates it everywhere that it
is used.

Resources:
• prepared algorithm descriptions that require constants.
8CT.04 Explain the need Introduce this activity by asking learners to consider the following
for searching algorithms. questions:
When did you have to search for something?
8CT.05 Describe and use
What were you trying to find?
linear searches.
How did you search?
Hold a class discussion to gather a range of responses. Learners
should describe the different times they may have searched and
how they approached it, such as:
• looking for lost keys by looking through each place in
each room one at a time
• looking for a file in a computer by using the search
function or checking each folder in turn.
Provide some examples of scenarios where a searching As learners have not yet learned about arrays or lists,
algorithm might be needed, for example: they may benefit from seeing a table with data, such as:
• finding the smallest item in a list
Learning objectives Suggested teaching activities and resources Additional notes
• finding the largest item in a list They can then consider how they would search this
• looking for a specific record in a file data for a specific value.
• finding a special event
• finding an event that happened on a specific date.
Put learners into pairs and ask them to discuss what they would
do to find the answers.

Ask each pair to feed back on their discussions and support the
class towards agreeing a process of checking each item in turn
until they find the item that they are searching for.

Explain that there are different searching algorithms, and some


are more effective than others depending on the data being
searched. Explain that one of these is known as a ‘linear search’.
Define a linear search as
checking each item in turn starting with the first item and
continuing this search until:
• the required item is found
• all items have been searched and the correct item is not
found.

Put learners into small groups and give each group a set of cards
with numbers on, for example playing cards. Ask the groups to
place their cards face down and then search for a specific value
by performing a linear search. They will need to turn one card
over at a time, starting with the first one. If they find the number
they are looking for, they stop. If the card is not the one that they
are looking for, they put it back face down and check the next
one.
Ask each group to write a sequence of steps, presented as an This will not be expected in pseudocode or a flowchart
algorithm, to instruct someone else to perform a linear search. but in sentences, for example:
They should swap their algorithms with another group and then • Look at the first card.
test each other’s algorithms using the cards. o If it is it the value you are looking for, stop.
Learning objectives Suggested teaching activities and resources Additional notes
oIf it is not the value you are looking for, put the
The groups should make any necessary corrections based on the
card back face down so you cannot see it.
feedback from other groups. Each group member should then
o Turn over the next card.
write a personal copy of the final version. They should annotate
this with their own notes about searching algorithms, and linear • Repeat until you find the required card.
searches in particular. Ask the following questions to help them to
structure their notes:
What is a searching algorithm?
Answer: a series of steps that looks for specific data in a
set of data
Why are searching algorithms needed?
Answer: to find data within a set of data
Give an example of a searching algorithm.
Answer: a linear search
How does a linear search work?
Answer: each item is checked in turn, starting with the
first

Resources:
• example scenarios showing when searching algorithms
may be used
• playing cards, or similar
Unit 8.3 Programming
Learning objectives Suggested teaching activities and resources Additional notes
8P.01 Outline the purpose of Introduce this unit by holding a class discussion about the purpose of Make sure that learners understand the
program libraries. libraries. Ask the following questions to guide the discussion: important difference between book and
Have you ever been to a library? program libraries:
8P.03 Identify and know how
to use library functions in
What does a library allow you to do? • if you borrow a book from a book library,
Why do you use a library? you need to return it after the set period
text-based programs.
Elicit that the purpose of a library is to enable readers to borrow and of time
read books for a set period of time, without paying a fee. • if you use code from a program library,
you can use it indefinitely.
Link this definition to program libraries in computing. Explain that
program libraries contain pre-written and tested modules, or self-
contained programs, that can be called by another program. Program
libraries save programmers time in writing and testing newly created
functions. Libraries also allow less experienced programmers to
include complex things that they may not yet be able to create for
themselves. Therefore, using libraries in this way can simplify the
whole programming process.
Introduce learners to a Python library, for example random or math. You may need to introduce the concept of
Demonstrate how to import the library into a program, for example: random numbers at the beginning of this
from random import random activity. The purpose of random numbers is to
import math generate random events, select random
choices or make decisions, such as which
Put learners into pairs and give each a description and example of at move a computer should make during a game.
least one library function. For example, from random: Explain that truly random numbers do not exist
randomNumber = random.randint(0, 100) in computers, because there is always an
The 0 is the smallest number that will be randomly generated, the 100 algorithm within the operating system to
is the largest number that will be randomly generated. generate them.
Learning objectives Suggested teaching activities and resources Additional notes
Demonstrate how to import the library and how to use its function. Regardless of which library you use, random
Then set each pair a series of problems that will enable them to or math, learners will benefit from a short
experience using the library for themselves. For example: explanation of the other as this will help them to
• generate a random number between 1 and 10 visualise what different libraries can do.
• generate a random number between 1 and 4, output a different
message depending on the number selected
• simulate the roll of a dice (between 1 and 6)
• simulate a Magic 8-Ball game, where the user asks a question,
then one of a series of five answer options (yes, no, maybe,
not sure, try again) is output; the answer will be determined by
random numbers between 1 and 5.

A random decimal number can be generated using multiple-digit


numbers and then dividing by the power of 10. For example:
randomNumber = random.randint(10, 20)/10
will generate numbers with 1 decimal place between 1.0 and
2.0
randomNumber = random.randint(250, 550)/100
will generate numbers with 2 decimal places between 2.50 and
5.50
randomNumber = random.randint(250, 550)/10
will generate numbers with 1 decimal place between 25.0 and
55.0.

As an alternative to the random library, you could use math. For


example:
radius = 10 It would be useful to recap common circle
circleArea = math.pi * radius * radius calculations before introducing math.pi, such
circleCircumference = math.pi * radius * 2 as the circumference of a circle as either 𝜋𝑑 or
Where math.pi returns the value of pi. 2𝑟𝜋. You may decide to teach learners about
program libraries when they are learning about
roundUp = math.ceil(2.66) 𝜋 in Mathematics.
Where the number in the brackets is rounded up to the nearest
whole number (integer).
Learning objectives Suggested teaching activities and resources Additional notes

roundDown = math.floor(2.66)
Where the number in the brackets is rounded down to the
nearest whole number (integer).

Example problems for math could include:


• enter a decimal number and round up and round down
• get the computer to output a decimal number; ask the user to
round it down and enter the result, check if the answer is
correct
• repeat as above, but with the user being asked to round the
number up
• repeat as above, but ask using a series of random numbers.

Support learners to recall their learning from this activity by asking


them to discuss the following questions in their pairs:
What is a program library?
Answer: A pre-written and pre-tested programs that can be
called in another program.
How do you use a program library in Python?
Answer: You import the library and then call the functions.
What are some examples of program libraries in Python?
Answer: random and math.
Why are program libraries useful?
Answer: They save time in writing new functions. They are
also pre-tested so should already work.
The pairs should make notes of their answers, then share these with
another pair and agree on their answers as a group. Hold a class
discussion and invite each group to share their agreed answers.
8P.04 Know how to develop Support learners to recall what is meant by conditional, or selection,
text-based programs with statements by asking:
What are the three component parts of a conditional
statement?
Learning objectives Suggested teaching activities and resources Additional notes
conditional (selection) Answer: the condition; the code to run if true; the code to run if
statements. not true
What is a conditional statement?
8CT.06 Understand and use
Answer: A question that has a true or false answer.
rules using AND, OR and
What is the symbol for a condition in a flowchart?
NOT to create logic within
Answer: a diamond
algorithms.
8P.06 Know how to develop What are the conditional operators that we can use? In mathematics, the equivalents of the last
text-based programs which Answer: <, >, =, !=, <=, >= three of these symbols are: ≠, ≤ and ≥.
use rules involving AND, OR Give each learner either a blue or orange coloured card and display a
and NOT. list of statements that use AND, OR and NOT conditions. For
example:
If you are holding a blue card hair AND your height is more
than 1.5 metres, stand up.
If you are NOT holding an orange card, sit on the floor.
If you are holding a blue card OR you are holding an orange
card, clap your hands.
If you are holding an orange card OR your height is more than
1 metre, jump.
After each statement, discuss the meaning of the AND, the OR and These statements can be linked to truth tables
the NOT. For example: and logic gates if learners have prior knowledge
• in the first statement, both conditions must be true for learners of these.
to stand up • AND requires both conditions to be true
• in the NOT statement, it reverses the condition, so only those (1 1) to result in true.
who are holding a blue card sit on the floor • OR requires one or both conditions to be
• in the first OR statement, either condition being true will result true (1 1, 1 0, 0 1).
in a clap • NOT reverses the statements (1 becomes
• in the second OR statement, anyone holding an orange card or 0, 0 becomes 1).
is taller than 1 metre would jump.

Introduce learners to the format of conditional statements in Python,


using singular if, as well as if else. The format of these is as
follows:
Learning objectives Suggested teaching activities and resources Additional notes
IF:
if condition:
code to run if true
IF else:
if condition:
code to run if true
else:
code to run if false
Use different examples and ask learners what they mean, and what The indents are important in Python. Once the
the results will be. These examples could include: user has typed the colon and pressed enter, the
number = 10 cursor should be auto-indented to the correct
if number == 10: position within the IDE. In the first example
print("Yes") below, the print statement is not in the if
else: statement so it will always run; in the second
print("No") example, it is indented so it will only run if the
if statement is true:
first = 20 if x = 10:
if first < 20: print("Hello")
print("Less than 20")
else: if x = 10:
print("20 or more") print("Hello")
Introduce the Boolean operators (AND, OR, NOT) in the same way, In Python, the Boolean operators ‘and’ and ‘or’
for example: are written in lower case and need to have a
first = 10 condition on either side, for example:
second = 20 If x = 10 and y = 10:
if first < 20 and second < 20: If x = 10 or y = 10:
print("Both less than 20") The Boolean operator ‘not’ needs to be before
a condition, for example:
if first < 20 or second < 20: If not x = 10:
print("At least one is less than 20")

value = True
if not value:
print("False")
Learning objectives Suggested teaching activities and resources Additional notes
else:
print("True")

Put learners into pairs and give them a series of programs to write that
use the conditional statements if and else and progress to
conditional statements AND, OR and NOT. For example:
1. Take a number as input from the user and check whether it is
greater than 10. Repeat by checking if it is less than 10.
Answer:
numberInput = int(input("Enter a number"))
if numberInput > 10:
print("Greater than 10")
else:
print("Less than or equal to 10")

2. Ask the user a question and output whether their answer was
correct.
Answer:
answer = int(input("What is 2 * 2?"))
if answer == 4:
print("Correct")
else:
print("Incorrect")

3. Ask the user to guess what number is stored in the computer.


Output ‘Correct’ for a correct guess or ‘Incorrect’ for an
incorrect guess.
Answer:
number = 100
guess = int(input("Guess what number I am
thinking of"))
if guess == 100:
print("Correct")
else:
print("Incorrect")
Learning objectives Suggested teaching activities and resources Additional notes

4. Ask the user to enter a number between 1 and 10 and output


whether they did this successfully or not.
Answer:
numberInput = int(input("Enter a number
between 1 and 10"))
if numberInput >= 1 and numberInput <= 10:
print("Success")
else:
print("Incorrect")

5. Take two numbers as input from the user and output the
number which is larger.
Answer:
first = int(input("Enter a number"))
second = int(input("Enter a number"))
if first > second:
print(first)
else:
print(second)

6. Ask the user a ‘yes’ or ‘no’ question and check if they


answered yes with different combinations of upper and lower
case letters, such as ‘yes’, ‘Yes’ and ‘YES’.
Answer:
answer = input("Is a dolphin a mammal?")
if answer == "yes" or answer == "YES" or
answer == "Yes":
print("Correct")
else:
print("Incorrect")

7. Ask the user to enter two test results. If either test result is
greater than 90, tell them that they passed.
Answer:
Learning objectives Suggested teaching activities and resources Additional notes
result1 = int(input("Enter result 1"))
result2 = int(input("Enter result 2"))
if result1 > 90 or result2 > 90:
print("Pass")

8. Ask the user to enter two test results. If both results are greater
than 90, tell them that they passed with distinction.
Answer:
result1 = int(input("Enter result 1"))
result2 = int(input("Enter result 2"))
if result1 > 90 and result2 > 90:
print("Distinction")

9. Ask the user to answer a question and use NOT to output


whether they are incorrect.
Answer:
answer = int(input("What is 10 * 10?"))
if not(answer == 100):
print("Incorrect")
else:
print("Correct")

Resources:
• coloured cards for two colours, for example blue and orange.
8P.02 Identify and describe Introduce this activity by asking: Learners should already be familiar with
data types in text-based What is a data type in programming? Integer, Real and String in Computing. If they
programs, including Integer, Answer: data that is put into categories, so the program knows are not, introduce these as:
Real and Boolean. what is expected • Integer stores whole numbers
8P.05 Know how to develop What data types do you already know? • Real stores decimal numbers
text-based programs using Answer: Integer, Real and String • String stores characters that can include
data types, including Integer, What is the difference between an Integer and a Real number? letters, symbols and numbers that cannot
Real, String and Boolean. Answer: an Integer is a whole number, a Real number is a be used mathematically.
decimal number Learners may encounter slightly different
definitions of Integer and Real in Mathematics,
Learning objectives Suggested teaching activities and resources Additional notes
What is a string? but should understand the definitions above for
Answer: one or more characters that can include letters, Computing.
symbols and numbers that are not used in mathematics
calculations, such as telephone numbers or credit card
numbers.

Introduce the concept of a Boolean data type as ‘true’ or ‘false’ We usually spell ‘Boolean’ with a capital B.
because it can only be one of two values. Demonstrate this by saying Explain that this is because it is named after a
a statement such as person: George Boole.
‘10 is less than 11’
and agreeing that this is ‘true’.
Ask:
What else in programming only has two values?
Answer: binary is 1 or 0

Support learners to associate the Boolean data type ‘true’ with the
binary number ‘1’, and ‘false’ with ‘0’.
Give learners a table of data and ask them to identify the most Learners often identify any numeric-only values
appropriate data type for each. Here is an example table, with the as being Integer or Real. However, numbers
expected answers in italics : that are not used in calculations, such as
telephone numbers or credit card numbers, will
always be a string. Explain that if the number is
never used in a calculation, it is a string.

Integer data types cannot start with a 0. Any


leading 0s will be removed. Therefore, any
integer that needs to have leading 0s, such as
an ID number, will need to be stored as a
string. In this table, if the ID number of the book
was stored as an integer, it would be 1182738,
which might be the ID number of a different
book.
Learning objectives Suggested teaching activities and resources Additional notes
Explain the use of Boolean data as a ‘flag’. Explain that it is used to
indicate if something has occurred, or is valid or correct. If the flag is:
• true then it is positive, meaning that it has occurred, it is valid
or it is correct
• false it is negative, meaning that it has not occurred, it is not
valid or it is incorrect.

Put learners into pairs and give them a set of programs that will
require the use of data of different data types. For example:
1. Ask the user a series of questions that require answers as In Python, for True and False to be recognised
integers, reals and strings. Store whether they answered each as Boolean they need to be True or False.
question correctly in a different variable as True for correct, This is case sensitive.
and False for incorrect.
Answer:
answer1 = int(input("What is 1 + 2?"))
if answer1 == 3:
answer1Result = True
else:
answer2Result = False
answer2 = float(input("What is 3 / 2?"))
if answer2 == 1.5:
answer2Result = True
else:
answer2Result = False
answer3 = input("Enter True if 2 = 3? Or False
otherwise")
if answer3 == "True":
answer3Result = True
else:
answer3Result = False

2. Ask the user to enter True or False. Output a different


message depending on their answer.
Learning objectives Suggested teaching activities and resources Additional notes
Answer:
entered = input("Enter True or False")
if entered == "True":
result = True
else:
result = False

if result == True:
print("Yes you entered True")
else:
print("Oh no, you did not enter True")

3. Design a questionnaire and write a program to ask the user the When taking input from a user, Python will store
questions and store their answers. all data as a string. To convert it to an integer
Answer: the code int() needs to be used, for example:
firstName = input("Enter your first name")age answer = int(input("What is 1 +
= int(input("Enter your age")) 2?"))
pocketMoney = float(input("Enter the amount of For a real number, the key word float is
pocket money you get")) needed instead of int.
likeGames = input("Enter True if you like
video games") To check for Boolean data, the value would
if likeGames == "True": need to be compared to the String value. It will
likeGames = True not actually store it as a Boolean data type
else: unless done manually, for example:
likeGames = False result = input("Enter True or
False")
4. Write a program that displays some data and asks the user for if result == "True":
the most appropriate data type for each. Output whether they result = True
are correct or incorrect. This would not be done practically in
Answer: programming, but it is good experience for
print("What data type is more appropriate learners to manipulate the values.
for:")
answer1 = input("True or False") Depending on your context, you may need to
if answer1 == "Boolean":
use a different example to pocket money.
Learning objectives Suggested teaching activities and resources Additional notes
print("Correct") Pocket money can be defined as ‘a small
else: amount of money given regularly to a child by
print("Wrong it is Boolean") an older family member’.

answer2 = input("1, 4, 6, 12")


if answer2 == "Integer":
print("Correct")
else:
print("Wrong they are integers")

answer3 = input("horse, spider, rabbit")


if answer3 == "String":
print("Correct")
else:
print("Wrong it is a string")

answer4 = input("1.22, -2.93, 99.00001")


if answer4 == "Real":
print("Correct")
else:
print("Wrong they are real numbers")

Extend this activity using OR conditions to allow different spellings, for


example by checking if the user has entered "Integer" or "integer" or
"int" or "Int".

Display the following questions and allow learners to reflect on them,


based on their experience during this activity:
Did you encounter any problems while writing the programs?
What were the problems?
Were these to do with the data types?
How did you fix them?
Allow learners to discuss their responses in pairs and then ask:
Did you both encounter any problems that were similar?
Did your partner offer any useful solutions to the problems?
Learning objectives Suggested teaching activities and resources Additional notes

Conclude by asking:
What is the difference between a String and a Boolean data
type?
Support learners to recall that Boolean is only ‘true’ or ‘false’, while a
String can be any combination of characters.

Resources:
• data type table or worksheet
8P.07 Use an iterative Introduce this activity by asking: Learners are likely to have already used
process to develop programs. What do we mean by iteration or repetition? iterative development when writing programs
Elicit that it is about doing the same thing more than once. Then ask: without realising. This is because programs
When you write programs, do you always get them right first rarely work first time and, therefore, they are
time? changed and then tested again.
If not, what do you do when a program is wrong?
Do you always write the whole program in one go, or do you
write a small part and then add to it?
Why do you do it this way?

Display the term ‘iterative process’ and explain what we mean by an


iterative process in software development, for example:
An iterative process is the process of writing part of a program,
testing it and editing it, then adding to the program, testing it
and editing it, and then adding to it continually until a final,
working, program is produced.

Put learners into pairs and give them a description of a program that
takes a user’s grades or marks in a range of subjects and then outputs
which subjects they should continue to study. For example, high
scores in Maths and Computing could create an output recommending
that the user continues to study Maths and Computing.
Learning objectives Suggested teaching activities and resources Additional notes
Ask the pairs to discuss, plan and then create their program. Tell them
that they must use the ‘discuss, plan, create’ cycle iteratively until their
program is complete.

Invite pairs to demonstrate their program and to explain:


• how they used an iterative approach
• how they know it was iterative
• whether they thought this process was useful
• whether the iterative process seemed the natural way to
approach the task.

Support learners to make notes on iterative development processes.


They can choose their own format for their notes but could be guided
by the following questions:
What is iterative development?
Answer: Repeatedly editing and testing a program until it is
complete.
Have you used iterative development before without knowing
it?
Did you find iterative development useful?
How could iterative development be useful when you have a
very large program to write?
Answer: The program can be split it into smaller parts, with
those parts being worked on individually. New features and
parts can then be added to the program throughout the
iterative process.
8P.10 Know how to test Tell learners that this activity is about testing the programs that they
algorithms using suitable create. Ask:
data. Why do we need to test programs?
Answer: to make sure that they work; to check there are no
8P.09 Explain the need for
errors; to check that they give suitable responses to
using a range of test data.
unexpected input
How do we test that a program works?
Learning objectives Suggested teaching activities and resources Additional notes
8P.08 Know how to develop Answer: we use the program, for example by entering data
and apply test plans. and pressing buttons, then check whether it does what is
expected to meet its criteria

Demonstrate a program that only works with some data and not with The second condition is incorrect. It should be
other data, for example: number <= 10. If the user inputs 10, the
number = int(input("Enter a number between 1 program will produce the wrong output.
and 10 inclusive"))
if number >= 1 and number < 10:
print("Success")
else:
print("Wrong")
Demonstrate that testing this program with:
• 5 will output Success
• 15 will output Wrong
• 10 will output Wrong, so it will not work as expected.
Hold a class discussion on why it is not sufficient to test a program Make it clear that not every possibility can be
with one or two examples of test data. Elicit that a range of data tested. Instead, developers need to make a
should be used. reasonable judgement about when they can
state that their program works.
Give learners a blank test table for a program. For example:
Explain that sometimes a program can be
tested with a wide range of data but can still
contain an error that has not been thought of,
such as in a gameplay situation when a
character bumps into an object and can no
longer move.
Put learners into pairs and ask them to use the table to create a test
plan for the program that they looked at earlier in the activity. They
should plan to test it with a range of data, but they should not perform
the test yet. An example of the output from this activity might be:
Learning objectives Suggested teaching activities and resources Additional notes

Ask pairs to share their completed test table with another pair and to
add any further tests that they think are appropriate. The pairs should
then test the program and complete the ‘Actual result’ column.

Ask learners to select a program they have written previously and to


produce a test table for it. Ask them to swap their test tables with a
partner to discuss whether they have included sufficient tests, with a
sufficiently wide range of data. They should then test their programs to
check whether they work as expected.

Hold a class discussion to consider the following questions:


Why did you test your program?
Answer: To make sure it works and to check whether it does
what is expected to meet its criteria. Testing also checks
Learning objectives Suggested teaching activities and resources Additional notes
whether the program is able to give a suitable response to an
unexpected input.
Why should you test a program using a range of data?
Answer: It may work with one input but not any other inputs.
Testing with a range of data also checks whether the program
works in all reasonable cases.

Resources:
• test table template
• learners’ programs from earlier activities.
8P.11 Know how to develop Check learners’ prior experience of using programmable devices, and Learners may have used beebots and
programs that allow two or support them to recall this experience, by asking: micro:bits in earlier stages. For example, they
more physical devices to What devices do you know how to program? may have given directional instruction to a
interact. What commands can you remember for these devices? movable device or may have programmed
What can you make these devices do? simple traffic -control systems.
Ask learners to access programs they have previously written for the
devices and to discuss in pairs what each line of code does and how it If no example programs are available, give
works. learners an example such as the following,
which uses MakeCode:
Hold a class discussion on the interaction of devices in the 'real world'
by asking:
What devices do you know that interact?
Support learners to suggest examples such as:
• computer to printer
• laptop to mobile phone
• thermostat to heating.
Ask:
How do devices communicate? What do they send?
Elicit that devices send messages in binary and that they could be
transmitted by, for example, cable, wi-fi, satellite or Bluetooth.
Learning objectives Suggested teaching activities and resources Additional notes

Demonstrate how to make two or more devices interact. This will The function and methods will depend on the
depend on the devices that you use, but common methods include: devices used. Some devices may need a
• detecting the movement of another device, for example one physical connection (cable) between them;
device stops moving when another device lights up others may use sensors to detect each other;
• receiving and responding to a signal from another device, for while others may use wi-fi or Bluetooth to send
example a device flashes a light when another device tells it to. messages to each other. Set tasks appropriate
Show learners how to program the device to: for the devices that you are using.
• send a message or signal to another device
• receive a message of signal from another device
• use a sensor to record the action or signal from another
device.
For two devices to interact, learners will need to program both devices
individually.
Learning objectives Suggested teaching activities and resources Additional notes
Put learners into pairs or groups and give them a problem that they
need to create a program to solve. Example problems for micro:bits
could be:
• Device 1 needs to send device 2 a maths question. Device 2
needs to calculate the answer and send it back. Device 1
needs to tell device 2 whether it is correct or not.
• Similar to the problem above, but device 2 outputs the
question, then the user has to input the answer which is sent
back to device 1.
• Device 1 sends signals to device 2 telling it how to move. For
example, the user could input the command to move forward
on device 1; device 1 sends a message to device 2, which
then moves forward.
• Two devices need to move around an area. When they sense
each other nearby, they turn towards each other and flash a
message.

Invite pairs or groups to demonstrate their solution and to describe:


• how the devices interact
• the method of interaction (cable, Bluetooth, wi-fi)
• the code that was used.

Hold a class discussion to review the learning from this activity. Ask
the following questions to support the discussion:
How did you test your program?
How did you connect your devices?
How did you make sure that the devices communicated? Did
they communicate by cable, wi-fi or Bluetooth?
How did they know what to do?
Did you encounter any problems or errors in the development?
What were they? How did you correct them?

Resources:
• micro:bits
Learning objectives Suggested teaching activities and resources Additional notes
• example code, using Make Code
• problems for learners to solve.

You might also like