0% found this document useful (0 votes)
13 views42 pages

G7 T3 Notes 0860

Uploaded by

otabeknasimov19
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)
13 views42 pages

G7 T3 Notes 0860

Uploaded by

otabeknasimov19
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/ 42

Unit 9.

1 Algorithms and data

Learning objectives Suggested teaching activities and resources Additional notes


9CT.01 Follow, understand, Provide learners with some algorithms that are written in pseudocode. Learners should already be able to follow and
edit and correct algorithms that Place learners into pairs and ask them to discuss the following understand pseudocode algorithms. This
are presented as pseudocode. questions in relation to each of the algorithms that they are given: activity is an opportunity to reintroduce
What does the algorithm do? pseudocode and to help learners to recall how
What are the key features of the algorithm? pseudocode works. It also provides an
What programming techniques are used in the algorithm? opportunity for them to follow algorithms of
Hold a class discussion to elicit the key observations from each pair increasing complexity.
and to identify and address any misconceptions. The key features that
learners identify should include the inputs, the decisions within the
algorithm and the result or output. The programming techniques
should include inputs, outputs and variables.
Give learners an algorithm that performs a single task and ask them to An expected answer would be:
make a change to it, for example: number1 = input("Enter a number")
change this algorithm so it multiplies the numbers instead of number2 = input("Enter a number")
adding them result = number1 * number2
number1 = input("Enter a number") print(result)
number2 = input("Enter a number")
result = number1 + number2
print(result)
Repeat the process with different algorithms that increase in
complexity, for example:

1. Adding several calculations An expected answer would be:


Change this algorithm so that it subtracts the second input number1 = input("Enter a number")
from the first, then multiplies this new value by the first input number2 = input("Enter a number")
and outputs this value result = (number1 - number2) *
number1 = input("Enter a number") number1
number2 = input("Enter a number") print(result)
result = number1 / number2
print(result)
Learning objectives Suggested teaching activities and resources Additional notes

2. Changing the outputs required An expected answer would be:


Change this algorithm so that it outputs the name and age that name = input("Enter your name")
the user has input in a sentence age = input("Enter your age")
name = input("Enter your name") print("Hello ", name, " you are ",
age = input("Enter your age") age, " years old")
print("Hello ", name)

3. Including selection statements An expected answer would be:


Change this algorithm so that it only outputs "Valid" when the value = input("Enter a number")
number is greater than 0 if(value > 0):
value = input("Enter a number") print("Valid")
if(value > 10):
print("Valid")

Change this algorithm so that if the user enters the "+" symbol, An expected answer would be:
the two numbers are added together number1 = input("Enter a number")
number1 = input("Enter a number") number2 = input("Enter a number")
number2 = input("Enter a number") symbol = input("Enter the symbol")
symbol = input("Enter the symbol") if(symbol == "*"):
if(symbol == "*"): print(number1 * number2)
print(number1 * number2) elseif(symbol == "+"):
print(number1 + number2)

4. Adding further elements to an algorithm An expected answer would be:


Change this algorithm so that is also checks if the number value = input("Enter a number")
entered is less than or equal to 1000 if(value >= 10 and value <= 1000):
value = input("Enter a number") print("Valid")
if(value >= 10):
print("Valid")
5. Changing the whole purpose and function of the algorithm An expected answer would be:
x = 0
Learning objectives Suggested teaching activities and resources Additional notes
Change this algorithm so that it inputs a direction from the user y = 0
(up, down, left or right). When up is entered, the y value is direction = input("Enter up, down,
increased by 1. When down is entered, the y value is left or right)
decreased by 1. When right is entered, the x value is increased if(direction == "up"):
by 1. When left is entered, the x value is decreased by 1 - y = y + 1
x = 0 elseif(direction == "down"):
y = 0 y = y - 1
x = x + input("Enter x value change") elseif(direction == "left"):
y = y + input("Enter y value change") x = x - 1
elseif(direction == "right"):
x = x + 1
else
print("Invalid direction”)
Discuss the changes learners have made by asking questions such
as:
What programming tools did you make use of?
Did you encounter any problems?
How did you overcome these errors?

In their pairs, give learners the description of a program and an


algorithm that does not meet the requirements, for example where a
calculation is incorrect. Ask learners to identify the problem with the
algorithm, and to explain how this should be corrected.

Ask each pair to share their corrected algorithm with the class, and to
explain the changes that they made. Hold a class discussion to
identify any differing responses or any different approaches that were
taken to correct the algorithm. This discussion will also provide an
opportunity to identify and discuss any misconceptions amongst
learners.
Resources
• Key vocabulary card to support learners’ recall of pseudocode
• Range of pseudocode algorithms
• Description(s) of problems that require an algorithm
Learning objectives Suggested teaching activities and resources Additional notes
9CT.02 Follow flowchart or Evaluate learner's prior knowledge and understanding of programming Learners are only required to understand count-
pseudocode algorithms that and iteration by asking: controlled loops at this stage. These can be
use loops. What is repetition? limited to the use of ‘FOR Loops’. Although
Elicit that repetition is something that happens more than once. condition-controlled loops can be used for
9CT.07 Predict the outcome of counting, they are not required at this stage.
algorithms that use iteration. If it does not get covered by the previous answer, follow up by asking:
What does repetition mean in a computer program?
Elicit that repetition in a program is a piece, or section, of code that
runs more than once. Then ask:
What programs have you written, or seen, that use repetition?

Display the format of a FOR loop in pseudocode, that is suitable for A count-controlled loop, or FOR loop, iterates
Python, for example: the number of times specified in the loop. Link
for variable in range (start, end): the name of the iteration to the function i.e.
code 'count' controlled means it is keeping count of
something. The variable used in the FOR
Demonstrate this format in use, with examples, and demonstrate the statements has a starting value, and then
output, for example: counts from that number to the end value.
This loop will output the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
for count in range(0, 10):
print(count)
Ask specific learners to demonstrate how they followed the algorithm
with different values, for example (5, 9). This demonstration could be
supported by questions such as:
What is the output if number 0 is changed to 1?
What is the output if number 10 is changed to 20?

Give learners a slightly adapted loop in pseudocode, for example:


for count in range(0, 20):
print(count + 1)
Ask them to identify the differences and to predict how this will change
the purpose of the program. Repeat this with further changes in
different elements of the program, for example:
for x in range(1, 11):
Learning objectives Suggested teaching activities and resources Additional notes
print(count - 1)

Display a flowchart with a count-controlled loop. Demonstrate how to When using count-controlled loops in flowcharts
keep track of the counter variables and how to change and check its a variable needs to be declared with a start
values. Explain that this differs from pseudocode because in a FOR value, for example: count = 0
loop the four elements are given in one line, for example: The value will need to be checked against the
for count in range(0, 10) gives end value, for example: if count = 10
• the variables (count) The value will need to be incremented
• the start value (0) (increased) each time through the loop, for
• the end value (10) example: count = count + 1
• and for indicates the incrementing
In a flowchart these need to be separated and placed in the correct
position, for example:
• the variable is declared before the loop
• the start value is given before the loop
• selection is used to check the variable value
• this then increments the value within the loop
An example would be:
Learning objectives Suggested teaching activities and resources Additional notes

Ask learners to identify the key features of the count-controlled


iterations in the flowchart. They should do this by referring to:
• the variable declared before the loop
• the start value given before the loop
• the selection used to check the variable value
• the incrementing the value within the loop.

Give learners two or more flowcharts with count-controlled iterations,


for example to output the numbers between 1 to 100. Ask them to
identify the common features between the two. Elicit all of the key
features, including the variables and start values, etc.

In pairs, give learners several algorithms, presented as a variation of


flowcharts and pseudocode, to follow that make use of count-
controlled loops. Example algorithms could be:
• an algorithm that takes 10 numbers from the user and adds them
together
• an algorithm that outputs the 5 times table
Learning objectives Suggested teaching activities and resources Additional notes
• an algorithm that asks the user how many numbers they want to
enter, then loops this number of times, taking a number from the
user each time, before it calculates and outputs the average.
Ask the pairs to:
• discuss what the outcome of the program will be
• then follow the algorithms individually
• join another learner to discuss if their predication was accurate.

Ask learners to create a mind map of all that they have learned during
this activity. The content of their mind maps can be informed by the
following questions:
What is repetition in an algorithm?
Answer: A piece of code run more than once
What is a count-controlled loop?
Answer: Code that runs a set number of times
When can a count-controlled loop be useful in algorithms?
Answer: When something has to happen a set number of
times
What are the key features of a count-controlled loop?
Answer: A counter with a starting value, an end value and an
increment.

Resources
• Example algorithms that use count-controlled loops, both
pseudocode and flowcharts
• Descriptions of algorithms that require count-controlled loops
9CT.08 Compare and contrast Give learners a description of a problem and then display an algorithm At this stage, care should be taken to not go too
algorithms designed for the that is supposed to solve the problem. For example: far into the comparison of algorithms. Learners
same task to determine which Problem: A program needs to ask the user to enter the mark only need to primarily consider whether an
is best suited to the purpose. they got in a test and output if they got a pass (40+), merit algorithm meets the requirements. They can
(60+) or distinction (80+). then evaluate the amount of code and the
Algorithm in python: number of variables used.
Mark = input("Enter the mark")
if(Mark >= 40):
Learning objectives Suggested teaching activities and resources Additional notes
print("Pass") Stage 9 learners do not need to be concerned
elif(Mark >= 60): with run-time, memory usage, effective
print("Merit") constructs, constants vs variables or local vs
elif(Mark >= 80): global variables.
print("Distinction")
else:
print("Ungraded")

Ask:
Does this algorithm meet the requirements?
Elicit that this algorithm does meet the requirement.

Repeat this with algorithms that do, and do not meet the requirements. The correct algorithm here should be:
An example of an algorithm that doesn’t meet its requirement is: Temperature = input("Enter
Problem: A program needs to take a number between -10 the temperature in celsius")
and 40 from the user as a temperature in Celsius, and convert Fahrenheit = Temperature *
it to Fahrenheit. The calculation required here is ‘multiply by 1.8 + 32
1.8, then add 32’. print(Temperature + " in
Algorithm: celsius is " + Fahrenheit + "
Temperature = input("Enter the in fahrenheit")
temperature in celsius") The yellow highlighting signifies the corrections
Fahrenheit = Temperature + 32 * 1.8 that need to be made to the original.
print(Temperature + " in celsius is " +
Temperature + " in fahrenheit")

For this example, ask:


What does this algorithm do instead?
What needs changing to make it work?

Display a list of some elements that impact the efficiency of an When displaying these algorithms, ask learners
algorithm, for example: to identify the variables, inputs and outputs in
• number of lines of code (which impacts the file size) the pseudocode. Questioning such as this will
• number of variables used (which impacts the memory usage). help to check whether learners are following
what it is that is being explained.
Learning objectives Suggested teaching activities and resources Additional notes
Display two different algorithms for each feature, such as two
algorithms that solve the same problem but where one uses many
more variables and lines of code. For example:
Problem: Take 3 numbers as input, add them together and
output the result.
Algorithm 1:
number1 = input("Enter a number")
number2 = input("Enter a number")
number3 = input("Enter a number")
value1 = number1 + number2
total = number3 + value1
print(total)
and
Algorithm 2:
number1 = input("Enter a number")
number2 = input("Enter a number")
number3 = input("Enter a number")
print(number1 + number2 + number2)
Elicit that the second program uses fewer lines of code which means
the file size will be smaller. It also has one less variable therefore,
when running, it will use less memory.

Ask learners to each write an algorithm to solve a problem, for


example:
write a program that asks the user to enter a distance in
metres or feet, and to then convert it into the other unit.
Once they have written their algorithms, ask learners to work with a
partner to compare the two algorithms. The pairs will need to discuss
each algorithm to consider ideas such as ways of making their
algorithms more efficient. Each learner can then reflect on the benefits
of the pair discussion and feed these back as part of a class
discussion.

Resources
Learning objectives Suggested teaching activities and resources Additional notes
• Multiple algorithms that solve problems in different ways
• Description of a problem that requires an algorithm, that can
be written in many different ways
9P.02 Identify and describe Introduce this activity by asking: If learners are not familiar with the given data
data types in text-based What data types have you used in programming? types, introduce these by displaying a range of
programs, including Integer, What is an example of each data type? different items of data and asking learners to
Real, Character, String and Learners should already be familiar with Integer, Real, String and group them. For example, putting all the words
Boolean. Boolean data types. together, the numbers, the 'true' and 'false'
together. Show learners how these are
Ask learners: grouped into the given data types.
What can be stored in a string?
Elicit that a string can include:
• lowercase letters
• uppercase letters
• numbers
• symbols.
Learning objectives Suggested teaching activities and resources Additional notes

Introduce the ‘character’ data type by explaining that it only stores one It may be useful to clarify the purpose of
single character, instead of the option to store multiple characters in a character vs string and the benefits - it saves
string. memory space. When a string variable is
declared it has memory reserved for more data,
In pairs, ask learners to think of and discuss scenarios where only one but a ‘char’ is limited and therefore has a fixed
character may need to be stored. The pairs may identify elements memory size. Learners will also need to know
such as: that not all languages support the character
• entering a choice from an onscreen menu, for example 1, 2, 3 data type, for example Python only has string.
or a, b, c
• when accessing or splitting up a string or selecting specific
characters from a string
• storing a value to compare an input to.
Ask each pair to join with another pair to make a group of four. The
group should agree their top three scenarios and share these with the
rest of the class.

Display examples of data that can be entered into a computer


program, for example:
• 10
• 50
• "a"
• "bob!"
• TRUE
• "house"
• 11.738.
Ask learners to identify the most appropriate data type for each item
and to justify their choice. Ask the class to vote for the data type and
then select one learner to justify their choice.

The answers in this example would be:


Learning objectives Suggested teaching activities and resources Additional notes
Give learners a text-based program that has already been written, answer1 - integer
which includes different types of data. As an example, this could be a answer2 - Boolean
quiz program that asks users to enter different answers. Ask learners answer3 - real
to identify the most appropriate data type for each data item to be answer4 - integer
entered, and to write this alongside it. An example program could be: answer5 - string
answer1 = input("What is 1 + 2?")
answer6 - string
answer2 = input("An owl is a bird, true or
answer7 - integer
false?")
answer3 = input("How much will I spend if I answer8 - character
buy 5 items at $0.50 each?")
answer4 = input("What is the current year?")
answer5 = input("Identify a colour that starts
with the letter P")
answer6 = input("What does RAM stand for?")
answer7 = input("How many GB is 300MB?")
answer8 = input("Answer the first letter of
your first name")

To consolidate and check learners’ understanding of this topic,


facilitate a class discussion based upon the following questions:
• What are the 5 data types?
Answer: Integer, real, string, char and Boolean
• What data would you store in an integer?
Answer: Integer = whole numbers
• What data would you store in a real?
Answer: Real = decimal numbers
• What data would you store in a string?
Answer: String = one or more letters
• What data would you store in a character?
Answer: Character = one letter, number or symbol
• What data would you store in Boolean?
Answer: Boolean = true or false
• What is the difference between a string and a character data
type?
Learning objectives Suggested teaching activities and resources Additional notes
Answer: A ‘string’ stores one or more characters, a ‘character’
only stores a single character.
• Why are different data types used in programming?
Answers here will include:
o to stop invalid data entry
o to allow for calculations on numeric forms
o limiting the data that can be used
o saving memory space
o stopping invalid data being entered.

Resources
• List of example data to be entered into a computer, at least
one for each data type
• Text-based programs that make use of data of each data type
9P.01 Explain the purpose of a Describe a scenario of a program that needs to store the first and last At this stage, learners do not need to know
1-dimensional array. names of all of the learners in a school. Ask: what is meant by a ‘1-dimensional’ array. They
How many variables will you need to store this data? should be able to use arrays with 1 dimension.
Elicit that the answer will depend on the situation within the school, for
example, a school with 300 learners will need 2 variables for each Although the programming of arrays is not
learner, one for first name, and one for last name, which will mean 600 required at this stage, it would be beneficial to
variables in total. introduce learners to the concepts of identifiers
and indices, for example Colours[0], so that
Ask: they are already familiar with these references
What problems does this many variables cause? when they need to program them in later units.
Elicit that:
• defining each variable individually will take time Hard coding means that the value of the data
• remembering the identifiers will be difficult becomes fixed.
• each variable will need to be 'hard-coded'.
Introduce arrays as a means of storing multiple items of data under Learners are only required to understand the
one identifier. Explain that this allows for lots of data to be stored purpose of arrays at this stage but accessing
without needing a variable for each item. and manipulating the data will allow them to
gain a better understanding of its purpose and
how it will function.
Learning objectives Suggested teaching activities and resources Additional notes
Display a table with indices above and data in each space, for
example:

Ask specific learners questions, for example


What is the data in index 1?
Answer: Blue
What will happen if I change the data in index 3 to Grey?
Answer: The word ‘Green’ would be crossed out and replaced
with ‘Grey’.

In pairs, give learners a series of arrays, each containing indices and


data. For example:
Colours:

Numbers:

Countries:

Provide each pair with a series of questions and ask them to look at
the example arrays to find the answers. Example questions could be:
What is in Colours[5]? Purple
What is the result of Numbers[0] + Numbers[1]? 11

Ask each pair to swap their answers with another pair. Before
discussing the answers, each pair should compare their own answers
with those of the other pair and consider whether they need to make
Learning objectives Suggested teaching activities and resources Additional notes
changes to their own answers. Any outstanding differences should
then be discussed by the group of four and a final outcome agreed.

Each group should then share their final answers as part of a whole
class discussion. Any further differences should be discussed until
agreement over the final, and correct, answer has been achieved.

Resources
• Examples arrays with indices and data
• Set of questions to access data from given arrays
Learners may become confused by the
similarities between the shapes of the AND and
the OR gate. Explain the similarities and the
differences, so that learners are given regular
opportunities to express their understanding of
these two symbols.

At this stage learners do not need to be able to


create circuits that include many gates, a
maximum of 3 gates is sufficient.
Learning objectives Suggested teaching activities and resources Additional notes
Learning objectives Suggested teaching activities and resources Additional notes

In mathematics the order of operation is:


Brackets
Indices
Division
Multiplication
Addition
Subtraction
• If learners are unfamiliar with sound waves,
then draw one to show the different values.

Learners do not need to understand how


different sounds are stored in the waves, such
as how the amplitude and frequency affects the
sound produced. They just need to understand
that the wave height has values, and these can
be recorded and converted into binary.

Learners should identify digital sound wave is


not identical to an analogue sound wave. For
Learning objectives Suggested teaching activities and resources Additional notes
example, it is only recording some of the
values, not every part of the sound, therefore:
• if the wave was measured more times, it
will be more precise
• if it is measured less times, it will be less
precise.
The digitising of sound is the turning of the
wave into binary numbers.
9CT.05 Describe and use Provide learners with a dictionary and ask them to find the definition Learners do not need to be able to write or
binary searches. for a particular word. Explain that they need to start by opening the follow an algorithm to perform a binary search.
dictionary at the centre and decide whether the word they are looking They need to know that, for a binary search to
comes before or after the word that they see at the centre. Learners be successful, the data needs to be put into an
should then repeat this until they find the word that they are looking order; this could be ascending or descending.
for. Ask:
Is this method faster than looking through the dictionary from A common misconception is that searches only
the start? Or from the end? work with numbers, because these are what
When will this search be slower than starting at the beginning are commonly used in examples. Learners
of the dictionary? should have experience of searching text.
Elicit that, if the search item is near the start, searching in this way will
be slower. Ask: Another common misconception is that all
What would happen if the words in the dictionary were not in searches are on data that is in ascending order.
alphabetical order? Learners should also have experience working
Elicit that it would not be possible to use this method because the data with data in descending order.
is not in an order. Ask:
Does this limit when this searching algorithm can be used?
Elicit that the answer is yes, because the data needs to be in recorded
in a searchable order.

Demonstrate how to do a binary search by displaying a series of


numbers, in ascending numerical order, in a row. Ask learners to find
a particular number, and explain that they need to find the position of
that number. Demonstrate how to compare the number with the
middle number, for example:
• if not equal then:
Learning objectives Suggested teaching activities and resources Additional notes
o select the numbers to the left if it is less than the middle
number
o select the numbers to the right if it is greater than the
middle number
o discard the remaining numbers.
• repeat this process until the correct number has been found or
until there are no elements left.

Repeat this process with numbers in different positions in the set of


numbers, as well as with numbers that do not exist in the set. Explain
what to do when there is an even number of cards e.g. if there are 10
cards then the middle card is the 5th or 6th (either can be chosen as
long as used consistently) in each search.

Place the learners into pairs and give each pair a set of, up to 10,
cards. Use a set of playing cards. Ask the pairs to put the cards into
order, ascending or descending, and then to turn the cards face down.
Name a specific card and ask the pairs to use a binary search to find
out if they have that card.

Repeat the process of performing a binary search, this time giving


learners a set of cards with words on, for example ten colours. Ask the
learners to work in their pairs to perform a binary search on the word
cards, based upon the first letter of each word. For colours such as
‘Brown’ and ‘Blue’, learners will also need to consider the second
letter of each word in the searches.

Ask each pair to write a set of instructions on how to perform a binary


search. They should then swap their instructions with another pair,
who should follow the instructions precisely to see if they work. If the
instructions do not work, the second pair should identify the changes
or improvements that need to be made.
Learning objectives Suggested teaching activities and resources Additional notes
Hold a class discussion to elicit each pair’s experience of creating,
and checking, the instructions for a binary search. This discussion
could be structured around the following questions:
How easy or difficult is it to write a list of instructions to perform
this task?
What changes did you have to make to your instructions?
Provide an opportunity for each of their pairs to speak and use this as
an opportunity to address any misunderstanding or misconceptions.
Then ask:
How can you turn this into an algorithm?
Learners may find it helpful to limit their thinking here to a sequence of
steps rather than thinking about flowcharts or pseudocode.

Summarise what has been covered in this activity and ask:


Why are searching algorithms important?
Elicit that these algorithms allow particular data items to be found in a
collection of data. Then ask:
Why are there multiple searching algorithms and not just one?
Elicit that different algorithms are more appropriate in different
scenarios. Learners may benefit from recalling earlier learning about
linear searches when answering this question and comparing these
with the searches that they have used in this activity. Ask:
How practical do you think it would be to do a linear search for
a particular definition in a dictionary?

Resources
• Dictionaries or similar, such as phone books
• Playing cards, or other numbered cards
Unit 9.3 Programming
Learning objectives Suggested teaching activities and resources Additional notes
9CT.03 Know how to create Introduce this unit by checking learners’ prior knowledge of There are a range of possible standard flowchart
algorithms using flowcharts flowcharts and pseudocode. Ask: symbols, the ones listed here are those that match
and pseudocode. What are the standard flowchart shapes? the ones used in the Cambridge International
What does an arrow in a flowchart show? qualifications:
Answer: The direction of flow • Rectangle for process
What rules does pseudocode have? • Rectangle with rounded corners for start
Answer: There are no set rules, but standard programming and stop
symbols should be used instead of English-style sentences • Parallelogram for input and output
When are flowcharts and pseudocode used? • Diamond for selection.
Answer: When designing algorithms and solutions to problems

Display a flowchart, for example:

The matching pseudocode for this flowchart would


be:
num1 = input("Enter a number")
num2 = input("Enter a number")
total = num1 + num2
print("The total is ", total)
Learning objectives Suggested teaching activities and resources Additional notes

A flowchart solution to this algorithm would be:

Ask learners to convert this flowchart into pseudocode. They should


compare their response with a partner and discuss any differences.
They should consider if these differences are valid or whether there
are errors in one, or both, pseudocode algorithms.

Repeat this activity with flowcharts of increasing complexity, for


example:
• by introducing multiple operations
• then introducing selection statements.

Give learners a pseudocode algorithm, for example:


number1 = input("Enter a number")
number2 = input("Enter a number")
number3 = input("Enter a number")
number4 = input("Enter a number")
Learning objectives Suggested teaching activities and resources Additional notes
if(number1 > number2 and number1 > number2
and number1 > number3 and number1 >
number4):
print(number1, " is the largest")
elif(number2 > number3 and number2 >
number4):
print(number2, " is the largest")
elif(number3 > number4):
print(number3, " is the largest")
else:
print(number4, " is the largest")
Ask them to present this pseudocode as a flowchart. They should
then compare their responses with a partner and identify any errors,
or to determine if they have different, but still accurate, flowcharts.

Give each pair the description of a problem, for example:


Freya wants to work out how much money she will have left
at the end of the month. She needs to enter the amount of
pocket money she gets each week for 4 weeks. She then
needs to enter the 5 products she has bought and how
much they cost. The program then needs to output how
much money she will have left.

In pairs, ask learners to write a pseudocode algorithm to solve this


problem. Each pair should then swap their solution with another,
and test whether they work. To support their testing, provide
learners with some input data, for example:
• the amount of pocket money received each week
• a list of items and their costs.
A pseudocode solution to this problem would be:
Hold a class discussion to summarise this task. This discussion week = input("Enter the amount
could be prompted by the following questions: of money you get a week")
Did your solutions solve the problems? totalMoney = week * 4
Did you find any errors?
Learning objectives Suggested teaching activities and resources Additional notes
What were the errors? product1 = input("Enter the cost
How did you solve them? of the first item you bought")
How did you test whether your solution solved the problem? product2 = input("Enter the cost
of the second item you bought")
Resources: product3 = input("Enter the cost
• Set of flowcharts for learners to convert to pseudocode of the third item you bought")
• Set of pseudocode algorithms for learners to convert to product4 = input("Enter the cost
flowcharts of the fourth item you bought")
• Set of problems showing algorithms totalLeft = totalMoney -
product1 - product2 - product3 -
product4
print("You will have ",
totalLeft, " money left")
9CT.04 Know how to use Display the term ‘sub-routine’ and ask a learner to explain their
predefined sub-routines in understanding of its meaning. Ask other learners to add to the
flowcharts or pseudocode. answer until a suitable definition has been achieved. Elicit that:
• a sub-routine is a self-contained program that that can be
called from other programs
• sub-routines can be used multiple times in an algorithm and
can be used across different algorithms.

Display a list of instructions for actions that include a subroutine, for


example:
Define: Action 1 = clap 3 times, jump twice, clap 3 times
Action 2 = turn around three times, clap 10 times

Ask learners to follow these sub-routines, by calling out the


following sequence of instruction:
Stand up
Action 2
Action 1
Sit down
Stand up
Action 1
Learning objectives Suggested teaching activities and resources Additional notes
Action 2
Action 1
Sit down

Hold a class discussion to determine learners’ understanding of


what they have done during this activity. Ask:
What did you do for Action 1?
How did you know what you had to do?
Why was it easier to write Action 1 instead of 'clap 3 times,
jump twice, clap 3 times' each time?

Remind learners that these are subroutines and help them to recall
the definition that was agreed earlier in the activity. Explain that a
sub-routine is:
A set of commands that is given an identifier and can be
called from anywhere in an algorithm.
Elicit that using subroutines means that:
• you do not need to write the same code every time it is used
• each small programme or algorithm only has to be written
once but can be used many times within a larger
programme or algorithm.

Display a flowchart subroutine that has already been written, for


example a subroutine that converts Celsius to Fahrenheit:
Learning objectives Suggested teaching activities and resources Additional notes

Also display a flowchart that makes use of the subroutine, for


example:

Ask learners to work in pairs to follow the algorithm. Ask one pair to
demonstrate the steps they followed, by explaining which
instruction they followed.
Learning objectives Suggested teaching activities and resources Additional notes
Give learners another flowchart, for example for a different
conversion. Ask them to draw a flowchart that calls this flowchart as
a subroutine.

Display a pseudocode subroutine, for example:


subroutine addition()
firstNumber = input("Enter the first
number")
secondNumber = input("Enter the second
number")
result = firstNumber + secondNumber
print(firstNumber, " + ", secondNumber, "
= ", result)
endsubroutine
"yes", 2, 3 would give the output: "2 + 3 = 5"
Now provide a program that uses this subroutine, for example: "yes", 1, 19 would give the output: "1 + 19 = 20"
answer = input("Do you want to add two "no" would give the output "Program exiting"
numbers together?")
if(answer == "yes"):
addition()
else:
print("Program exiting") A subroutine for subtraction could be:
In pairs, ask learners to follow this program by entering different subroutine subtraction()
data, for example: firstNumber = input("Enter the first
• "yes", 2, 3 number")
• "yes", 1, 19 secondNumber = input("Enter the
• "no". second number")
result = firstNumber - secondNumber
Provide each pair with pseudocode subroutines for other print(firstNumber, " - ",
mathematical operations, for example subtraction and secondNumber, " = ", result)
multiplication, etc. Ask them to extend the above pseudocode endsubroutine
program by allowing the user to input which mathematical
calculation to follow, and then call the appropriate subroutine.
Learning objectives Suggested teaching activities and resources Additional notes
Summarise learner's work by asking
What is a subroutine?
Answer: A section of code with a name that can be called
from another program.
How do you call a subroutine in a flowchart or pseudocode?
Answer: Use its identifier.

Resources:
• Set of instructions to follow including one or more
subroutines
• Flowcharts that use subroutines
• Pseudocode that use subroutines
• Algorithms in flowchart or pseudocode that include pre-
written subroutines
9CT.06 Understand and use Gather learner's existing knowledge of count-controlled loops by
iteration statements, limited asking the following questions:
to count-controlled loops, What is iteration?
presented as either Answer: Code that repeats multiple times.
flowcharts or pseudocode. What is special about a count-controlled loop?
Answer: It runs a set number of times.
9CT.09 Combine multiple What features do you find in a count-controlled loop?
constructs (sequence, Answer: A variable, its start value and its end value.
selection, count controlled
iteration) to write algorithms Provide learners with a problem that will require them to make use A pseudocode solution, that follows python syntax,
as flowcharts or of a count-controlled loop, for example to output the numbers 1 to would be:
pseudocode. 100. In pairs, ask them to discuss how to solve the problem. One of for x in range (1, 101):
each pair should draw a flowchart to solve the problem, and the print(x)
9P.03 Know how to develop other should write a pseudocode algorithm. The pairs then compare In this example, ‘101; has been used because in
text-based programs with their ideas to see if they both perform the same function. python this would be where the loop stops. Other
count-controlled loops. languages would stop at ‘100’, for example:
Introduce learners to the syntax for programming count-controlled for x = 1 to 100
loops in a text-based programming language. In Python, this is: print(x)
for variable in range(startvalue, endvalue +1): next x
code
Learning objectives Suggested teaching activities and resources Additional notes
A flowchart solution would be:
Provide learners with a help sheet which details the format and
example programs that use count-controlled loops. Support them to
make their own notes so that they can refer to it when
programming.

Ask learners to convert their pseudocode or flowchart into a


program using a text-based program, using the sample programs
on their help sheet for guidance.

Display a problem that requires the use of a count-controlled loop,


for example:
a program needs a user to enter the cost of 20 items, and
then output the total and the average.
Ask learners to write a solution to the problem in the text-based
language.

Hold a class discussion to check learner’s confidence during this


task. This discussion could be informed by the following questions:
Did your programs work first time?
If not, how did you find the error?
How did you correct that error?

Resources:
• Problems that require the use of count-controlled loops
• Help sheet that provides the syntax for count-controlled
loops in text-based language
9P.04 Know how to access Display an array as a table, for example: Most arrays start with index 0, learners will need
data from an array using a reminding that the first element is in index 0, the
text-based language. second in index 1, etc.

Ask a series of questions to check learners’ understanding of this Python does not have an inbuilt array data
array, for example: structure. Instead it uses lists that have similar
What data is in index 0? functionality and can be used in place of arrays.
Learning objectives Suggested teaching activities and resources Additional notes
Answer: 30
What is the result of the data in index 2 + the data in index
3?
Answer: 35
What will be output if the pseudocode statement
OUTPUT(array[4]) is run?
Answer: 6

Display the syntax for accessing an array in a text-based language Python syntax involves the array name, followed by
and talk through it. Provide learners with a print-out of the syntax or square brackets with the index inside, for example:
ask them to make their own notes. Learners’ notes should include: myArray[0]
• how to output the value
• how to store it in a variable to perform other functions, for
example to add to another number.

In pairs, give learners a program that already has an array


declared, with values inserted, for example:
myArray = [1, 4, 5, 3, 15, 64, 27, 54]

Give the pairs a list of questions that requires them to write code to
produce an answer, for example: This would then need further code adding to enable
Output the second element in the array. it to do something with the value, for example:
Solution: print(myArray[1]) • to output it: print(myArray[0])
Output the data in index 0 in the array. • to store it and perform a calculation with it:
Solution: print(myArray[0]) myVar = myArray[0] + 2
print(myVar)
Gradually increase the complexity of the questions, for example by
requiring a combination of elements. Example questions include:
• Output the value in index 0 added to the value in index 5.
Solution:
print(myArray[0] + myArray[5])
or
Learning objectives Suggested teaching activities and resources Additional notes
firstNum = myArray[0]
secondNum = myArray[5]
total = firstNum + secondNum
print(total)

• Add together all the elements in the array.


Solution:
print(myArray[1])

For an additional challenge, the use of arrays can be combined with


a count-controlled loop, for example:
• Use a count-controlled loop to output each of the array
items in turn.
Solution:
for x in range(0, 8):
print(myArray[x])

Give each pair a program that makes use of two arrays, for
example one with text and one with numbers such as:
numberArray = [10, 5, 22, 100, 55, 82, 1]
colourArray = ["red", "purple", "blue",
"green"]

Provide a set of questions to write code to produce answers that


involve both arrays, for example:
• Output the third element in the number array with the
second colour.
Solution:
print(numberArray[2], " ", colourArray[1])

Hold a class discussion to review learners’ understanding of the


programming that they have done during this activity. This
discussion can include the following questions:
How do you access data in an array (list) in Python?
Learning objectives Suggested teaching activities and resources Additional notes
Answer: The array’s identifier [index] Some learners may identify that some languages
What is the first index in an array? start at 1. Also rounded brackets are used in some
Answer: 0 other programming languages.
What types of bracket do you surround the index with?
Answer: In Python, square brackets are used.

Resources:
• Array as a table with indexes and data.
• Program with a numeric array, and list of questions for
learners to write code
• Program with two arrays (one numeric and one text-based),
and a list of tasks that require learners to write code.
9P.05 Know how to develop Display a set of words stored in variables, for example:
text-based programs using word1 = "programming"
string manipulation, word2 = "MANIPULATION"
including length, upper case, Discuss the following questions:
and lower case. How many letters are in word2?
What would the data in word1 look like if it was all in
capitals?

Discuss the need for string manipulation by asking: Learners may need prompting, for example with
Why do you need to change any words entered into a scenarios such as entering a password to help
computer? them identify when these may be needed.
Answers could include:
• to access only certain characters
• to split an address
• to check what has been entered.
Why would you need to find out how many letters were in a
word?
Answer: To make sure it was the correct length, to check if
a word is entered.
Display the text-based programming language code for: In Python these would be:
• finding the length of a string len(string)
Learning objectives Suggested teaching activities and resources Additional notes
• converting a string to upper case upper(string)
• converting a string to lower case. lower(string)
Either give learners a handout that explains the syntax or ask them
to make notes.

Share a text-based program that has multiple strings stored in


variables, for example:
word1 = "PROGRAMMING"
word2 = "MaNiPuLaTiOn"
word3 = "eNCRYPTION"
word4 = "network"

Give learners a set of tasks to add to the program, for example:


• Output the length of the string in word1
Solution: print(len(word1))
• Convert word2 to lowercase and store it back in the
variable word2
Solution: word2 = lower(word2)
• Store the length of word3 in a variable
Solution: length = len(word3)
• Convert word3 to uppercase and output the result
Solution: print(upper(word3))
• Find and output the longest word
Solution:
length1 = len(word1)
length2 = len(word2)
length3 = len(word3)
length4 = len(word4)
if(length1 > length2 and length1 >
length3 and length1 < length4):
print(word1)
elif(length2 > length3 and length2 >
length4):
Learning objectives Suggested teaching activities and resources Additional notes
print(word2)
elif(length3 > length4):
print(word3)
else:
print(word4)

Give examples that combine strings with an array, for example:


wordArray = ["house", "car", "balloon",
"greenhouse"]
Ask learners to output the length of each word in the array. The
solution is:
for x in range(0, 4):
print(len(wordArray[x]))

Check learners’ understanding by holding a class discussion to


consider the following questions:
What does the function ‘length’ do?
Answer: It returns the length of the string.
What does the function ‘lower’ do?
Answer: It returns the string in lower case.
What does the function ‘upper’ do?
Answer: It returns the string in upper case.
What would you do to find the length of a string?
Answer: Use the function len
How would you find the shortest word?
Answer: Find the length of each word and then use an if
statement to compare them.
How would you check if the word a user has entered is long
enough?
Answer: Find the length of the word and use an if
statement to compare it to the minimum length.

Resources:
• Print-out of string manipulation syntax
Learning objectives Suggested teaching activities and resources Additional notes
• Programs with strings assigned and list of tasks to
complete

Learning objectives Suggested teaching activities and resources Additional notes


9P.09 Identify test Introduce this unit by discussing learner's prior understanding of testing. Example
data that covers questions could include:
normal, extreme and Why is it important to test a program?
invalid. Answer: To make sure that it meets its criteria and that it does not crash
Why do you need a plan to determine how to test a program?
9P.08 Know how to Answer: To make sure every element is tested
develop and apply Why do you need to test a program with a range of data?
test plans that include Answer: To make sure all acceptable values are accepted, and that any
normal, extreme and unacceptable values are rejected.
invalid data.
Discuss the term 'a range of data'. Introduce an example such as a program that Learners should focus on at least one
allows a user to enter their age as a whole number between 10 and 80 inclusive. of each three types of test data and
Ask learners to write all the different ages that they would enter to make sure the understand that it is not worth testing a
program works. Ask learners for their answers, then write these on the board and program with every possible piece of
group them into: normal test data. With extreme, it is
• normal – those that are acceptable, for example between 10 and 80 important to test all extreme points, in
inclusive the case of a number between 10 and
• extreme – those that are on the edge of acceptability, for example 9, 10, 80 80 there are two extreme points. Invalid
and 81 data should include:
• invalid - data that should be rejected, such as 8, 100, twenty, 11.73, -22. • data outside of the range,
• invalid data types
Display and explain the structure for a test plan, using some examples of the data • not entering any data when it is
given in the age checking example above. An example could be: expected.

Learners will also need to understand


that not all systems will have extreme
data, for example a system where
users need to enter 'yes' or 'no' will
only have normal ('yes', 'no') and
Learning objectives Suggested teaching activities and resources Additional notes
invalid (anything else). In this example,
there is no range for extreme.

Learners should already have some


experience of using test plans but, if
they do not, these can be introduced
here through examples for short
programs first and then building up to
Provide a scenario for a program, for example: longer, and more complex, systems.
a program needs to work as a calculator, taking two numbers as input, and
either + - / or * as an operator, then output the result.
Ask learners to work in pairs to design a test plan for this program. They should
include all three types of test data in their plan.
For this example, normal tests could
Ask the pairs to compare their plan with one other pair, and check that there is at include:
least one normal, extreme and erroneous piece of test data. • 10 20 +
• 5 100 -
Give learners access to a program and ask them to test it using their test data and • 89 22 /
to record the results. This could be done with a working program, or with a program • 33 1 *
that contains an error. As an example, the following program does not check for Extreme:
invalid data entry, beyond invalid numbers: • 0 20 +
number1 = input("Enter a number")
• -1 50 /
if(number1 < 0 or number1 > 100):
print("Invalid") • 100 2 *
else: • 101 66 -
number2 = input("Enter a number") Invalid:
symbol = input("Enter + - / or *") • Ten 20 +
if symbol == "+": • 22 one -
result = number1 + number2 • 11 99 multiply
elif symbol == "-":
result = number1 - number2
elif symbol == "/":
result = number1 / number2
else:
result = number1 * number2
Learning objectives Suggested teaching activities and resources Additional notes
print(result)

Ask learners to select a program that they have previously written and to develop a
test plan for that program. Ask them to swap with a partner to evaluate their test
plans and add any further tests that should be included in the plan. Ask the pairs to
work together to test the programs using their test plans.

Summarise the learning from this activity by asking learners to reflect on the
following questions:
What are the three types of test data?
Why do we test a program with normal data?
Why do we test a program with extreme data?
Why do we test a program with invalid data?
Would happens if a program is not tested thoroughly?
Learners should make personal notes in response to these questions but can
choose their own format for these notes, such as ‘question and answer’ or a visual
representation.

Resources:
• Example program
• Test plan template
9P.10 Identify a range Introduce this activity by asking: The syntax errors will depend on the
of errors, including What errors do you make when you write a program? programming language that is being
syntax, logic, and Can you recall any of your programs that did not work first time? What did used. As pseudocode does not have a
runtime errors. you do wrong? set syntax, syntax errors are not easily
Ask learners to make a note of up to three separate errors that they can recall. identifiable.
9P.11 Use trace They should answer the above questions for each of their errors on a separate
tables to sticky note.
systematically debug
text-based programs. Introduce and explain the following types of error: Learners need to understand runtime
• syntax - when the grammar of the programming language is broken, such errors, but it is not always possible to
as using ‘pint’ instead of ‘print’ simulate these, the most common ones
• logic - the program runs but it does not do what you intended, such as include invalid input data without
writing ‘+’ instead of ‘*’ validation, so that the program crashes.
Learning objectives Suggested teaching activities and resources Additional notes
• runtime - the program stops running and crashes when set criteria are met,
such as dividing by zero or an attempt to calculate with an invalid data type
for example trying to multiply 3 by "house".

Place three large sheets of paper around the room with one labelled ‘syntax’,
another labelled ‘logic’ and the third labelled ‘runtime’. Ask learners to review the
sticky notes that they created at the beginning of the activity and to place them on
the sheet that is relevant to the type of error that they identified. Hold a class
discussion to review the errors that have been listed and to identify any that have
been identified against an incorrect error type.

Place learners into pairs. Provide each pair with a program that contains multiple
syntax errors and ask them to identify, and then correct, those syntax errors. For
example:
total == input("Input the first number" * 2
for count in rnge(0 to 100)
value 2 = input(Enter the second number")
total = total+ value2
average = total / 100
output("Total is " * total, " average is , value2)

Discuss learners’ findings by asking the pairs to provide one syntax error. They
should also explain the correction that they made. The errors in this program are
highlighted in the version below:
total == input("Input the first number" * 2
for count in rnge(0 to 100)
value 2 = input(Enter the second number")
total = total+ value2
average = total / 100
output("Total is " * total, " average is , value2)

Introduce learners to trace tables, by explaining that the purpose is to provide a


structure for conducting a dry run of the code so that changes in values can be There is no correct way to complete a
identified and so that errors can be identified. trace table, other than to write every
Learning objectives Suggested teaching activities and resources Additional notes
change below the appropriate identifier.
Also explain that each variable in a program has its own column in a trace table and One method is to put every change on a
that there will also be a column for output. Explain a program line by line and new line, whilst another is to put each
write the changes on each line in the table. An example program for this part of the change directly below the previous value.
activity could be:
num1 = 10 Learners may be tempted to jump ahead
num2 = 20 in the algorithm and to predict its
num3 = 15 outcome, rather than walk it through line
total = 1 by line. It is therefore recommended that
if num1 > num2 and num1 > num3: they cover the code with a sheet of paper
total = total + num1 and only reveal it line by line as they are
elif num2 > num3: completing the trace table.
total = (total * 2) + num2
else:
total = total + num3 + num3
print(total)

The trace table for this example is:

In pairs, provide learners with an edited version of the last program, for example
where the numbers are input instead of stored and give them multiple sets of input
data to trace the algorithm. Ask the pairs for the outputs from the program for each
set of input data and discuss any differences.

Extend the use of trace tables by using different constructs such as a introducing a
count-controlled loop to trace.

Now provide each pair with a program that includes at least one logic error. As an
example, the following program should output the smallest number entered and the
largest number entered:
Learning objectives Suggested teaching activities and resources Additional notes
smallest = 100 A completed trace table for this input
largest = 100 data would be:
for x in range(0, 10):
number = input("Enter a number between 1 and 100")
if(number > largest):
largest = number
elif(number < smallest):
smallest = number
print("The largest is ", smallest)
print("The smallest is ", largest)

Give the pairs a set of input data, such as 98, 44, 82, 4, 18, 41, 27, 91, 3, 22. Ask
them to complete a trace table for the program to:
• identify the logic error
The logic error is that the largest does
• then identify how to remove this error. not work, it would need to be initialised to
a small value, for example: -1
Support learners to make personal notes based upon what they have understood
from this activity. The notes can be presented in a format of their own choosing but
should be informed by the following questions:
What are the three types of programming error?
Answer: Logic, syntax and run-time
What is an example of a syntax error?
Answer: A spelling mistake in a keyword
What happens when you have a logic error?
Answer: The program runs but does not produce the correct output.
What happens when you have a runtime error?
Answer: The program crashes.
What can you do to find a logic error?
Answer: Test the program with a range of data, including normal, extreme
and invalid. The program could also be tested through the completion one
or more trace tables.

Resources:
• Sticky notes
Learning objectives Suggested teaching activities and resources Additional notes
• Large sheets of paper
• Program with syntax errors
• Program with at least one logic error
• Example trace table with program
9P.12 Know how to Ask learners to think about the following questions: If a programmable device has not been
program physical Do you always program a solution to a problem correctly first time? used before, or a new device is being
devices to use data to If not, what do you do when it goes wrong? introduced, explain and demonstrate the
solve problems. Ask for a small summary of learners’ reflections on these questions and elicit that, commands that can be used. Learners
when errors occur, they make changes and improvements to their programs. may need time to program the device to
9P.06 Use iterative perform simple tasks to learn the syntax.
development on Explain how this process of improvement is called an iterative development.
software prototypes to Display the word ‘iterative’ and link the term to iteration in programming. Explain
produce solutions to that both uses of the word mean ‘repeating’. Describe iterative development as the
problems. process of continually adding to, and amending, a program until it meets the
requirements.
9P.07 Evaluate the
processes that are Recap learner's existing knowledge about a programmable device that they have
followed to develop used before, such as the micro:bit. Ask learners:
programs. What commands can you use with this device?
How can you control this device?
What can the device be programmed to do?

Place the learners into groups. Give each group a device and a description of a
problem. Explain that the groups need to write a program for the device that will
solve the problem. The problem must make use of data, for example where the
device receives data from an input and then produces an appropriate output. The problem, or problems, that you
Example problems: choose here will be determined by the
• a robot needs programming to move around a room, stopping and turning devices that you have available.
each time that it meets an obstacle
• using a pair of devices, one needs to encrypt a message and transmit it to
the second, which then deciphers and outputs the message
• creating a mathematics game for young learners where the device outputs a
question. The user then has to input their answer by pressing a button the
Learning objectives Suggested teaching activities and resources Additional notes
correct number of times and the device will then output an appropriate
message, image or sound, to indicate if the answer is correct.

Ask the groups to collaboratively develop a solution to the problem iteratively.


Ask each member of each group to write an evaluation of their iterative
development of the solution. Ask them to include:
• a description of how they developed their solution
• the successes
• the problems that were encountered and how these were overcome

Ask each group to present their solution to the problem, and to nominate one of
their members to give their evaluation of the process that they followed.

Ask each learner to consider the following questions about this activity and their
experience of working in their group:
How did you approach the problem?
How well did you work as a team?
Did you split tasks between yourselves, or did you all contribute to each
part? Did that method work?
Did you make use of iterative development?
Was the iterative development naturally occurring, or did you have to stop
and make sure you were using it?
The learners should make notes based upon their responses to these questions
and should reflect upon anything that they would do differently next time and why.

Resources:
• A set of devices for learners to program

You might also like