G7 T3 Notes 0860
G7 T3 Notes 0860
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)
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?
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 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")
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.
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.
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:
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.
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.
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
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.
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.
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.
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.
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)
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"]
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.
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
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)
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 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