0% found this document useful (0 votes)
366 views248 pages

Grade8 - DL&C Textbook

This document is an introduction to a Student's Book on computer science, detailing its content and structure, including various units focused on programming, network design, data management, and more. It emphasizes the importance of computational thinking and provides guidance on how to use the book effectively. Additionally, it outlines the endorsement process by Cambridge International and the environmental policies of the publisher, Hachette UK.

Uploaded by

reema kapur
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)
366 views248 pages

Grade8 - DL&C Textbook

This document is an introduction to a Student's Book on computer science, detailing its content and structure, including various units focused on programming, network design, data management, and more. It emphasizes the importance of computational thinking and provides guidance on how to use the book effectively. Additionally, it outlines the endorsement process by Cambridge International and the environmental policies of the publisher, Hachette UK.

Uploaded by

reema kapur
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/ 248

369825_FM_Cam_LSC_SB_001-007.

indd Page 1 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Computing

9
Ben Barnes
Margaret Debbadi
Pam Jones
Tristan Kirkpatrick
SERIES EDITOR:

Lorne Pearcey
369825_FM_Cam_LSC_SB_001-007.indd Page 2 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Endorsement indicates that a resource has passed Cambridge International’s rigorous quality-assurance
process and is suitable to support the delivery of a Cambridge International curriculum framework. However,
endorsed resources are not the only suitable materials available to support teaching and learning, and are not
essential to be used to achieve the qualification. Resource lists found on the Cambridge International website
will include this resource and other endorsed resources.
Any example answers to questions taken from past question papers, practice questions, accompanying marks
and mark schemes included in this resource have been written by the authors and are for guidance only.
They do not replicate examination papers. In examinations the way marks are awarded may be different.
Any references to assessment and/or assessment preparation are the publisher’s interpretation of the
curriculum framework requirements. Examiners will not use endorsed resources as a source of material for any
assessment set by Cambridge International.
While the publishers have made every attempt to ensure that advice on the qualification and its assessment is
accurate, the official curriculum framework, specimen assessment materials and any associated assessment
guidance materials produced by the awarding body are the only authoritative source of information and should
always be referred to for definitive guidance. Cambridge International recommends that teachers consider using
a range of teaching and learning resources based on their own professional judgement of their students’ needs.
Cambridge International has not paid for the production of this resource, nor does Cambridge International
receive any royalties from its sale. For more information about the endorsement process, please visit
www.cambridgeinternational.org/endorsed-resources
Cambridge International copyright material in this publication is reproduced under licence and remains the
intellectual property of Cambridge Assessment International Education.
Third-party websites and resources referred to in this publication have not been endorsed by Cambridge
Assessment International Education.
Hachette UK’s policy is to use papers that are natural, renewable and recyclable products and made from
wood grown in well-managed forests and other controlled sources. The logging and manufacturing processes
are expected to conform to the environmental regulations of the country of origin.
Orders: please contact Hachette UK Distribution, Hely Hutchinson Centre, Milton Road, Didcot, Oxfordshire,
OX11 7HH. Telephone: +44 (0)1235 827827. Email [email protected] Lines are open from 9 a.m. to
5 p.m., Monday to Friday. You can also order through our website: www.hoddereducation.com
ISBN: 978 1 3983 6982 5
© Margaret Debbadi and Pam Jones 2023
First published in 2023 by
Hodder Education,
An Hachette UK Company
Carmelite House
50 Victoria Embankment
London EC4Y 0DZ
www.hoddereducation.com
Impression number 10 9 8 7 6 5 4 3 2 1
Year 2027 2026 2025 2024 2023
All rights reserved. Apart from any use permitted under UK copyright law, no part of this publication may be
reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and
recording, or held within any information storage and retrieval system, without permission in writing from the
publisher or under licence from the Copyright Licensing Agency Limited. Further details of such licences (for
reprographic reproduction) may be obtained from the Copyright Licensing Agency Limited, www.cla.co.uk
Cover photo © ZinetroN - stock.adobe.com
Illustrations by Aptara, Inc.
Typeset in India by Aptara, Inc.
Printed in Bosnia and Herzegovina
A catalogue record for this title is available from the British Library.
369825_FM_Cam_LSC_SB_001-007.indd Page 3 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Contents
Introduction 4

9.1 Presenting choices: Combining constructs 8

9.2 Design your own network: Shape and size 55

9.3 Coding and testing: Game development for the micro:bit 88

9.4 Drilling down: How the processor handles instructions 129

9.5 Big Data modelling and analysis: Databases and


spreadsheets 160

9.6 An array of skills 198

Glossary 236

Index 242

3
369825_FM_Cam_LSC_SB_001-007.indd Page 4 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Introduction
About this book
Computer science is the study of computers, This Student’s Book will help you to understand
computing hardware and software, computer some of the key areas of computer science, such
networks and the design of computer programs. as:
It also includes the study of the way humans l network design
interact with computers and computing l algorithms and sub-routines
technology. l machine learning and Industry 4.0

Computer science is linked to all areas of the l one-dimensional arrays and string

world you live in today. It helps you to make manipulation


positive changes to the world you live in, and l databases, spreadsheets and Big Data
provides important tools and applications to help l software prototype development.
you solve a wide range of problems. Computer
science is continually evolving to provide new and This book also supports the learning objectives
valuable ways of improving your life and your within the five strands of the Cambridge Lower
interactions with the world around you. Secondary Computing framework:

● Computational thinking is built into create databases and spreadsheets to help


the tasks in this book. It looks at how with managing different types of data.
computing can be used to explore ● Networks and digital communication
and analyse data collected from the focuses on the methods used to transfer
world around you. It is also about the digital data between different computing
development of skills to support problem- devices and on how these devices are used
solving, for example how to describe a to support communication. In this book,
problem, and the data needed to solve that you will explore how different computing
problem, in a way that a computer can devices can be linked together to support
understand. data transfer and find out about the
● Programming explores the steps involved methods used to ensure that data is
in designing and creating a computer transferred securely and accurately.
program that can be used to carry out a ● Computer systems is about how computer
particular task. In this book, you will study hardware devices and computer programs
text-based programming languages such work together to support users in solving
as Python and explore how to program problems. It involves considering how
a physical computing device to solve a the hardware and software and the data
problem. input is processed, stored and then output,
● Managing data looks at how computers to help a user solve a problem. In this
and computer programs can be used to book, you will explore the network and
store, organise and manage different types communications devices used to transmit
of data. It also explores how that data can data and information around a computer,
be used to support problem-solving. In this and around the world, in the process of
book, you will learn how to use, edit and solving a problem.

4
369825_FM_Cam_LSC_SB_001-007.indd Page 5 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

KEYWORDS
sub-routine: standalone section of code that can Big Data: datasets that are too large or complex
be called from the main program for traditional data-processing applications, e.g.
machine learning: ability of a computer system to databases or spreadsheets, to process
learn over time prototype: initial product created for testing and
Industry 4.0: refers to how industry is combining reviewing, before a final product is released
electronics with new technologies, e.g. machine data type: classification applied to a data item
learning, artificial intelligence, robotics and green specifying which type of data that item represents,
energy e.g. in a spreadsheet some of the data types
one-dimensional array: series of items grouped available include currency, text and number
together under one identifier
string manipulation: process of changing the
format of a variable/string to allow it to be
analysed

This Student’s Book has six units:


9.1 Presenting choices: Combining constructs develops knowledge and skills using Python
to understand how to use a count-controlled loop and an array. You will plan an algorithm
and program with Python to act as a chatbot and ask a sequence of questions to help a
student make a decision on which options or areas of study to focus on.

9.2 Design your own network: Shape and size investigates how networks can be structured
in a variety of environments, providing scope to scale. It also covers ways in which networks
can be protected through design: how error-checking can work to improve transmission,
how machine learning is continuously improving the efficiency of utilities software and how
networks can be kept secure.

9.3 Coding and testing: Game development for the micro:bit develops your knowledge
and skills with the BBC micro:bit and MicroPython using count-controlled iteration and
arrays. You will create a MicroPython program to utilise the micro:bit as an element of a
‘What am I?’ game, developing your knowledge of using physical devices as part of game
development.

9.4 Drilling down: How the processor handles instructions looks at the steps a processor
carries out during the execution of a computer program. You will learn about the fetch–
decode–execute cycle and how program instructions are stored in lists that are run one at a
time. You will also learn why a range of language translators are needed to ensure that the
processor can understand and carry out program instructions users write. You will explore
logic circuits and learn about the benefits of machine learning and computerisation in a
range of industry and manufacturing areas.

9.5 Big Data modelling and analysis: Databases and spreadsheets explores the concept
and applications of ‘Big Data’. You will develop your data-modelling skills to create relational

5
369825_FM_Cam_LSC_SB_001-007.indd Page 6 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

databases of real-life models. You will learn how to use functions such as MAX, MIN, COUNT
and IF in spreadsheet models. You will investigate how to manipulate relational-database
models and spreadsheet models using complex queries and formulae, respectively.

9.6 An array of skills focuses on iterative development and developing a program over
time to meet a set of requirements. You will make use of all three programming constructs
(sequence, selection and iteration) and use arrays in the development of your program. You
will develop a game to improve knowledge of times tables and systematically debug and test
the solution using trace tables.

How to use this book


In each unit, you will learn new skills by completing a series of tasks.
These features appear in each unit:

Get started!
This box introduces the unit and gives you some questions to
discuss in pairs or small groups.

Learning outcomes
This box lists the learning outcomes that you will achieve in the
unit.

Warm up
This box provides a task to do in pairs or small groups to get the
learning started.
DID YOU KNOW?
This box provides an
SCENARIO
interesting or important
This box contains a scenario that puts the tasks in the unit into a real- fact about the task or
world context. section.

Do you remember?
This box lists the skills you should already be able to do before
starting the unit.

Learn
This box introduces new concepts and skills.

6
369825_FM_Cam_LSC_SB_001-007.indd Page 7 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Practise
This box contains tasks to apply and practise the new skills and
knowledge from the ‘Learn’ box.

Go further
This box contains tasks to enhance and develop the skills you
have previously learned in the unit.

Challenge yourself
This box provides challenging tasks with additional instructions
to support new skills.

Final project
This box contains a final project that encompasses all the
skills you have developed over the unit, in the context of the
Scenario. The tasks in this box can be used to support teacher
assessment of the learning objectives from the ‘Learning
outcomes’ box.

Evaluation
KEYWORDS
This box provides guidance on how to evaluate and, if necessary, Important words
test the Final project tasks. are shown in
emboldened orange
font and are defined
in this box. They
What can you do? also appear in the
Glossary at the back
of the book.
This box provides a summary of the skills you have learned in
the unit and can be used to support self/peer assessment of
the learning objectives.

Computational thinking
Most computational thinking skills are embedded into the These speech
Practise tasks. However, where you see this box, an individual bubbles provide
computational thinking skill is highlighted for your attention. hints and tips as
you complete the
tasks.
Student resource files, used in some of the ‘Practise’ boxes, are available
at www.hoddereducation.co.uk/cambridgeextras

7
369825_9.1_Cam_LSC_SB_008-054.indd Page 8 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit Presenting choices:


9.1 Combining constructs

Get started!
Have you ever wondered how a
computer program can help you
to make a decision? How does a
sequence of questions help you
work out what to do?
Questioning allows you to ask
specific questions and gain insight
through the answers. If structured
correctly, these questions can help
you to find a solution to a problem
or make a decision.
Try this game in pairs: One student
should think of an object and the other student must ask up to 20 questions to try to
guess what the object is. The questions can have a response of only ‘Yes’ or ‘No’.
Discuss with your partner:
● How did the questions help to narrow down what the object was?
● What questions did you start with and why?
● Did you plan the questions you would ask before you started?
● What would you do differently if you were to do this activity again?

Questioning is an effective tool and, when used correctly, can help KEYWORD
you find out about something or help to narrow down a selection.
chatbot: software
In this unit, you will develop a Python program to act as a chatbot. application that
A chatbot is a program that asks the user a series of questions, uses text to ask
questions to help
stores the answers and then uses the information to help the user to a user
make a decision.

DID YOU KNOW?


A chatbot is a software application that carries out an
online conversation with a human user and, through
questioning, helps to identify a suitable solution to a
problem.
You may have interacted with a chatbot on a website
that enables you to have a conversation without
human involvement. For example, if you do not want
to wait on a phone for someone to answer a query
about a product, a chatbot allows you to type in
specific questions and guides you to a solution.
A chatbot is also used by the music application Spotify
to allow users to search for, listen to and share music.

8
369825_9.1_Cam_LSC_SB_008-054.indd Page 9 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Learning outcomes
In this unit, you will learn to:
● follow, understand, edit and correct algorithms that are presented as pseudocode
● follow flowchart or pseudocode algorithms that use loops
● create algorithms using flowcharts and pseudocode
● use and explain iteration statements with count-controlled loops in either pseudocode
or flowcharts
● predict the outcome of algorithms that use iteration
● compare and contrast two algorithms for the same solution and decide which is better
suited to a task
● create an algorithm as a flowchart or pseudocode using more than one of these
constructs: sequence, selection and count-controlled iteration
● identify and explain the purpose of a one-dimensional array
● identify and describe data types in Python programs, including integer, real, character,
string and Boolean
● develop a Python program with count-controlled loops
● access data from an array using Python
● develop Python programs using string manipulation, including length, uppercase and
lowercase
● use iterative development on Python prototypes to create solutions to problems
● develop and apply test plans that include normal, extreme and invalid data
● identify test data that covers normal, extreme and invalid data
● identify and describe a range of errors, including syntax, logic and runtime errors
● use a trace table to debug errors in a Python program.

Warm up
You make decisions every day, such as what clothes to wear,
what to have for breakfast, what to take to school, and many
more. Some decisions can be difficult to make and you may need
to answer some questions to help you to choose. For example,
the flowchart on the next page could help you to decide what to
have for breakfast.
Each question helps to narrow down your options. The questions
lead on from one another in a sequence, and every question
has a ‘Yes’ or ‘No’ path to follow. These paths lead either to
another question or to the final output – the
decision. KEYWORD
flowchart: visual
In pairs, create a flowchart to help you
representation of
to make a decision, such as choosing a an algorithm
topping for a pizza.

9
369825_9.1_Cam_LSC_SB_008-054.indd Page 10 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Start

OUTPUT "Breakfast
options are toast,
cereal or fruit."

No No OUTPUT
Do you want toast? Do you want cereal?
"Fruit it is!"

Yes Yes

OUTPUT OUTPUT
"Have toast!" "Have cereal!"

No OUTPUT
Do you want milk?
"Start eating!"

Yes

OUTPUT "Add
milk to cereal!"

SCENARIO
You use technology in a wide range of ways, user a series of questions, store their answers
and when you need help it is not always and use this to help make a final decision. The
possible to speak to a person. A chatbot solution will:
allows a company to support their customers ● be presented as pseudocode to show the
to find a solution to their problem through algorithm for your chatbot program
questioning. ● use variables and/or an array to store the
Your school has asked you to create a chatbot answers to the questions asked of the user
program to interact with students during ● use a count-controlled loop
the selection of options or subject areas to ● follow an iterative process to design, develop,
continue to study. The chatbot will ask the test and review to create a final prototype.

10
369825_9.1_Cam_LSC_SB_008-054.indd Page 11 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Do you remember?
Before starting this unit, you should be able to:
✔ develop a Python program using an iterative process
✔ follow and understand an algorithm presented as pseudocode
✔ explain and use the rules AND, OR and NOT to create logic within an algorithm
✔ follow flowcharts and pseudocode algorithms that use conditional statements
✔ predict the outcome of algorithms that use pseudocode
✔ create a Python program that uses conditional statements
✔ create a program in Python that uses a range of different data types
✔ develop a Python program that uses rules involving AND, OR and NOT
✔ decompose a problem into smaller sub-problems to make it easier to solve
✔ identify and describe the data types in a Python program
✔ develop and apply a test plan to ensure a Python program or algorithm works correctly.

In this unit, you will use the Python need to install IDLE on your own personal
programming language. device:
1 Go to www.python.org/downloads
Python’s Integrated Development and
2 Select Download Python.
Learning Environment (IDLE) provides
features for creating, editing and running 3 Once downloaded, double-click on the file
programs. Before using Python, you will to open it and then choose Install Now.
4 Once IDLE has installed, it should appear
in your Start Menu.

Chatbots
Learn
Chatbots have become increasingly useful
to growing businesses as they strive to meet
customer demands. Instead of a customer
sitting in a queue to speak to someone about
the questions they have, they can use a
chatbot to answer their questions and
receive possible solutions. This is a
developing technology that has limitations,
so if the chatbot is unable to help it will
direct the customer to speak to a person. In
this way, chatbots filter the calls that need to
be answered by a person by offering quick
answers to the problems they can solve.
For example, an IT helpline may be able to support a selection of customers by asking
some key questions about the issues they have and using this to offer possible ways for
the customers to solve the problem themselves.

11
369825_9.1_Cam_LSC_SB_008-054.indd Page 12 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

There are two main types of chatbot:


● Rule-based chatbots
● Chatbots with artificial intelligence.

Rule-based chatbots have predefined questions built in, so they are structured and less
conversational. The questions do not evolve with the user’s answers and are limited to
the set questions that have been programmed to be asked. Examples include IT first-line
support to gain an understanding of a system error or a health chatbot asking questions
to determine the level of a health issue or how to advise on the next steps.
Chatbots with artificial intelligence (AI) offer intelligent conversations as the AI learns
from your selections and answers to guide the next question or offer advice. It is called
machine learning when a device learns over time. This type of chatbot is a developing
technology, but more of the basics of AI are being integrated into chatbots where they
learn from the user’s choices, for example song selections or programme selections guide
suggestions for future choices.

Practise
KEYWORDS
1 Discuss with your partner the difference between a rule- rule-based chatbot: chatbot
based chatbot and an artificial-intelligence chatbot. with a set of questions built
in that it asks and the user
2 Chatbots are integrated into websites to help the
answers
customer. In pairs, investigate how chatbots are used in
evolving: changing and
retail and support, and consider the following questions. improving
a What is the chatbot’s main function? artificial intelligence: ability
b Who is the chatbot for (what type of user, for of a computer system to
example, a teenager)? learn and develop its own
programming from the
c How does it use questions to offer a solution?
experiences it encounters
d What is good about this type of chatbot? machine learning: ability of
3 Discuss as a class the range of chatbots you have found a computer system to learn
and any similarities or differences between them. over time

Data types and collecting variable data


Learn
You have previously used different data types, such as
KEYWORDS
string and integer, when developing programs. Remember:
data type: classification
you need to consider the data type of any variable when applied to a data item
planning an algorithm. specifying which type of data
The data types are: that item represents, e.g. in
a spreadsheet some of the
● string: a series of characters surrounded by quotation marks data types available include
● character: a single letter, digit or symbol currency, text and number
● integer: a whole number program: instructions that
● real: also known as a float; this is a decimal number
tell a computer system how
to complete a task
● Boolean – True or False.

12
369825_9.1_Cam_LSC_SB_008-054.indd Page 13 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

A string is a series of characters, and the characters are placed inside quotation marks,
for example: "string". Some programming languages, such as Java, include a character
data type that is used to store a single letter, digit or symbol. However, Python does not
use this data type. Here is an example showing a character data type being set up in the C
programming language: char variableName = 'A'. The content of the variable is a single
character defined by the code char, and the content following the = is the single letter A.
If you want to use a number in an equation or comparison, you must set it as either an
integer or a real data type. The integer data type stores whole numbers, and the real
data type stores numbers that contain decimal places, for example 15.75. You should
also be familiar with the Boolean data type that stores either True or False; for example,
if age > 20: would generate a True or False outcome.
It is important to set the data type when creating a variable. The following program
should store two numbers the user enters, add them together and display the total.

However, when this program is run and the user enters 5 and 3, the output is shown as 53.

KEYWORDS
algorithm: step-by-step
instructions to solve a particular
problem
Python assumes that an input is a string unless it is told
string: sequence of characters
otherwise. Therefore, in this program it has linked the
that can be text, numbers or
numbers together to form a longer string, rather than symbols; quotation marks
adding them. This is called concatenation. To add the values around the characters define it
together, the computer needs to be told to store each input as a string
as an integer. Remember: this is done by adding int to the character: single letter, digit or
input statement. When you convert the value from one data symbol
type to another, it is called casting because you cast it. integer: whole number
real: also known as a float; a
decimal number
float: decimal number
concatenation: joining two
strings together
cast: change the data type of a
Now when the program is run it gives the result expected: variable

Consider a chatbot that is going to ask you how many hours you have free, what your
favourite activity is and how long the activity will take, and then output as a sentence how
much time you will have left when you have completed the activity. A table can be created
to plan the variables required and their data types. Here is an example.

13
369825_9.1_Cam_LSC_SB_008-054.indd Page 14 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Variable name Data type


hours Integer
activity String
activityTime Real
timeLeft Real

These values can be used to plan the algorithm as pseudocode:


START
hours = INPUT "How many hours do you have free?"
activity = INPUT "What is your favourite activity?"
activityTime = INPUT "How long will the activity take?"
timeLeft = hours – activityTime
OUTPUT "When you have completed" ,activity, "you will have" ,timeLeft, "hours left"
STOP

The data type is not shown in the pseudocode, so having a table with the variable names
and data types planned out clearly can help the programmer when they are creating the
code.
Remember: the name of a
You have already used int to set the data variable is important to ensure that
type to an integer in Python. To set the it tells you what it is storing. There are
data type as a real number, you use float two main naming conventions:
instead of int. In the program below, you camelCase: all lowercase; from the
can see that the variable ‘hours’ has been set second word, the first letter is capitalised
as an integer and the variable ‘activityTime’
snake_case: all lowercase; spaces are
has been set as a float (real). The variable replaced with an underscore ( _ )
‘activity’ does not have a data type set as it
will be stored as a string by default.

Notice that the output uses both text and the contents of variables. The text is encased in
quotation marks and a comma is placed between this and the name of the variable to be
used. A comma is added whenever the output changes between text and a variable.

KEYWORDS
pseudocode: textual representation of an algorithm
naming convention: the way a variable or array is named in programming
camelCase: all lowercase, and from the second word the first letter is
capitalised
snake_case: all lowercase, and spaces are replaced with underscores ( _ )

14
369825_9.1_Cam_LSC_SB_008-054.indd Page 15 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Practise
1 Discuss with your partner what this flowchart
Start
algorithm will do.
2 Copy the table below and add the variables
and data types that will be required when
adult = False
creating the program. cost = 7.95

Variable name Data type

activity = INPUT
3 Create the pseudocode to match the "Enter the activity"
flowchart algorithm.
4 Write the program code for the algorithm in
Python and save it as activityChatbotV1.py.
5 Test, using a test plan, that your program age = INPUT
works as expected. "Enter your age"

6 Discuss with your partner how planning the


variables and data types can help when
creating the program code.
7 Discuss with your partner the different data Yes
is age >= 18? adult = True
types, with examples, and identify which data
type is not used in Python.
No
KEYWORD
test plan: document that details the tests to be
carried out when a program is complete and Yes
if adult == True cost = 9.50
whether or not they are successful

No

OUTPUT "As you


are", age,"it will cost
you", cost,"to go",
activity

Stop

15
369825_9.1_Cam_LSC_SB_008-054.indd Page 16 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Developing in iterations
Learn
You have seen that a program is developed from an algorithm to program code. The initial
idea for the program can evolve throughout this process. When the programmer receives
the initial requirements, they have a starting vision. This vision, through development into
a prototype, may change or be adjusted. That is where the programmer needs to work
iteratively to take in any adjustments and apply them to the development. Iterative means ‘to
repeat’, and the development steps are repeated until the prototype is ready to be released.

A project can follow this iterative process.


Requirements: What does the finished product need to do?
Design: The algorithm is developed using flowcharts or pseudocode;
a trace table is used to help check the algorithm.
Develop: The program code is written.
Test: A structured test plan is used to check the program’s
functionality.
Review: The test plan outcomes are looked at and anything that is
not working as expected is fixed; any potential improvements that are
identified are added to the requirements for the next iteration; there
is a general review of whether the final program meets the initial
requirements, or whether another development cycle is needed.
Launch: The final program is released.

The program code itself can also be developed iteratively. The code can be broken down
into smaller sections, and these can be developed, tested and reviewed before the next
section of code is added.
As a programmer starts to write the code, developments can be considered. The initial
idea may grow or change as the program develops, and a new development iteration may
be required.
To develop the opening of a chatbot program for selecting the type of support a user
requires, you would start with the pseudocode.

16
369825_9.1_Cam_LSC_SB_008-054.indd Page 17 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Step 1: Investigate the pseudocode


The pseudocode shows the algorithm for a program to select from a range of options,
and the user’s answer is used to give a response.
START
OUTPUT "Welcome to this support chatbot"
OUTPUT "Please select from one of the following options"
OUTPUT "1 for products"
OUTPUT "2 for store locations"
OUTPUT "3 for special offers"
selection = INPUT

IF selection == 1 THEN
OUTPUT "Welcome to store products"
ELSEIF selection == 2 THEN
OUTPUT "The store locations are UK and USA"
ELSE
OUTPUT "Welcome to the special offers"
ENDIF
STOP

Step 2: Identify the variable and data type required in the program

Variable name Data type


Selection Integer

Step 3: Use the pseudocode to write the Python program

17
369825_9.1_Cam_LSC_SB_008-054.indd Page 18 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Step 4: Identify areas for improvement


When this program is run, the text is output and the cursor stays on the next line waiting
for the user to input their selection. It would help the user to have a prompt, for example,
stating the possible inputs: 1, 2 or 3.

The program is developed iteratively through testing and reviewing.

KEYWORDS
evolving: changing and improving iterate/iterative/iteration: repeat/repeated/
user requirements: tasks a user expects of an repetition
application trace table: technique for predicting step by step
prototype: initial product created for testing and what will happen as each line of an algorithm or
reviewing, before a final product is released program is run, and to identify errors

Practise
1 A pizza shop wants to develop a chatbot to allow customers to select their pizza.
Customers may choose between chicken and sweetcorn, spicy lamb, and margherita.
a Discuss with your partner how you can use iterative development to create a
prototype chatbot for the pizza shop.
b Make a list of the requirements for the finished chatbot.
c Plan the algorithm for the chatbot using pseudocode.
2 a Use your pseudocode algorithm to write the program code for the chatbot and save
it as pizzaChatbotV1.py.
b Test your code to make sure that it works as you expect.
c Review your chatbot prototype to make sure that it meets your list of requirements.
3 a The pizza shop have decided that they would also like to offer a veggie pizza.
Develop your program code to include this option and save it as pizzaChatbotV2.py.
b Review your chatbot protype to make sure it meets this new requirement.

18
369825_9.1_Cam_LSC_SB_008-054.indd Page 19 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Code tracers
Learn
When developing a solution from algorithm to program, it is important to test both the
algorithm and the program code. When testing the finished program, it can be easier to
see errors when you use a structured test plan to document the output based on a range
of inputs.
An algorithm is the plan for a program that needs to be created and can be developed
visually using a flowchart or textually as pseudocode. The algorithm needs to be checked
and tested before it is handed over to the programmer to develop the program code.
A variable is a temporary storage location in memory whose contents can be called and
edited at any time in the program. The contents of each variable can be mapped out in a
trace table to show where they change as a program runs. A trace table is a structured
approach like a test plan that can be used to look at the algorithm, or program code, and
follow the variables and conditions.
Look at the structure of a trace table.

Line Variable Condition Output

● Line: The line in the pseudocode algorithm or the step in the flowchart.
● Variable: You can put the name of the variable in the heading and make a note of
the value of the variable in the column each time it changes.
● Condition: The conditional statement that completes a check to see whether the
variable meets the set criteria; the output will be either True or False.
● Output: Where the program outputs the value stored in a variable.

Follow these steps to test this pseudocode using a trace table.


1 START
2 number = 5
3 IF number < 10 THEN
4 OUTPUT number + 5
5 ELSE
6 OUTPUT number – 5
7 ENDIF
8 STOP

Step 1: You can see that there is one variable in this pseudocode example: ‘number’. This
can be added to the second column in the trace table, under the heading ‘Variable’.
There is also a condition being tested (‘Is the number less than 10?’). This can be added to
the third column in the trace table, under the heading ‘Condition’.

19
369825_9.1_Cam_LSC_SB_008-054.indd Page 20 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Line Variable Condition Output


number number < 10

Remember that a conditional


statement such as number
< 10 is generating a
Boolean output, as the
outcome can be only True or
False.

Step 2: Look at the first line of the pseudocode. This just defines the ‘START’ and is not
added to the trace table.
Line 2: Here, the value 5 is set against the variable ‘number’. This is added to the first row
of the table. The line number is added to column 1 and the value stored in the variable is
added to column 2.

Line Variable Condition Output


number number < 10
2 5

Step 3: Line 3 has the condition IF number < 10 THEN. The value that is stored in the
variable ‘number’ at this time is 5, and this is less than 10, so the output is True. This is
added to the next row of the table.

Line Variable Condition Output


number number < 10
2 5
3 True

Step 4: Line 4 has an output. It will output the value that is stored in the variable ‘number’
plus 5. This is added to the next row of the trace table.

Line Variable Condition Output


number number < 10
2 5
3 True
4 10

Steps 5–6: Lines 5 and 6 would not be used in this instance as they would run only if the
condition on line 3 was False. This is not added to the trace table.
Steps 7–8: Lines 7 and 8 do not use the variable as they define the end of the selection
section and the end of the algorithm, so they are not added to the trace table.

20
369825_9.1_Cam_LSC_SB_008-054.indd Page 21 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

The trace table is complete, and the algorithm has Start


been tested. You can see the flow of the variable
‘number’ and how it is used throughout the
program when it is run.
password =
The lines are easily seen in pseudocode. Now look at "enter123"
an example with a flowchart. In the previous example,
the value stored in the variable ‘number’ was an
integer (a whole number). In this next example, the
value stored is a string (a series of characters). userInput = INPUT

Step 1: Create the table with the headings for the


variables, condition and output.

Line Variable Variable Condition Output


password userInput password == userInput if password == No OUTPUT
userInput "Access Denied"

Yes
Step 2: Look at instruction 1, which would be
line 1 of the code. This is the ‘start’ shape on the
flowchart and is not added to the trace table. OUTPUT
"Access Granted"
Line 2: The variable ‘password’ is created and the
string ‘enter123’ is assigned to it.

Line Variable Variable Condition Output Stop


password userInput password == userInput
2 enter123

Step 3: Line 3: The user enters their password, and the string they input is stored in the
variable ‘userInput’. For this test, the user is inputting the string ‘enter123’.

Line Variable Variable Condition Output


password userInput password == userInput
2 enter123
3 enter123

Step 4: Line 4: The condition is if password == userInput. This is checking whether


the string stored in the ‘password’ variable matches the string stored in the ‘userInput’
variable. This will generate a Boolean outcome of True or False. The two variables do
match so the outcome is True. This is added to the next line of the truth table.

Line Variable Variable Condition Output


password userInput password == userInput
2 enter123
3 enter123
4 True

21
369825_9.1_Cam_LSC_SB_008-054.indd Page 22 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Step 5: Line 5: As the outcome to the condition is True, the output is ‘Access Granted’,
and this is added to the next line of the truth table.

Line Variable Variable Condition Output


password userInput password == userInput
2 enter123
3 enter123
4 True
5 Access Granted

The trace table is complete.


A trace table can also be created to check what will happen if the user enters a different
string for their input; for example, the trace table below shows the output if the user
enters the string ‘enter321’.

Line Variable Variable Condition Output


password userInput password == userInput
2 enter123
3 enter321
4 False
5 Access Denied

Trace tables are a useful tool for anyone planning a program. They help the programmer
to carry out a dry-run test on an algorithm, to check the values of variables through a run
of a program, and to find and fix any errors.

KEYWORDS
flowchart: visual representation of an algorithm
pseudocode: textual representation of an algorithm
variable: named memory location that can store a value
trace table: technique for predicting step by step what will happen as each
line of an algorithm or program is run, and to identify errors
criteria: set of rules that must be met
selection: choice to be added to a program using if… elif… else and the
next instruction executed in the program is decided by the outcome of a
condition
integer: whole number
string: sequence of characters that can be text, numbers or symbols;
quotation marks around the characters define it as a string
truth table: breakdown of a logic circuit, listing all possible operations the
logic circuit can carry out
dry run: process of working through an algorithm manually to trace the
values of variables

22
369825_9.1_Cam_LSC_SB_008-054.indd Page 23 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Practise
You have seen that a trace table can be used to trace the flow
of a variable through an algorithm displayed as pseudocode
or as a flowchart. A trace table can also be used with a Python
prototype program to find and fix errors.
1 Open the file FoodSelectionChatbot.py provided by your
teacher. The program is a prototype for a chatbot to help you
to select a food to eat. Using the file:
a Copy and complete the trace table below when the input is 1.
b Complete the trace table when the input is 2.
c Complete the trace table when the input is 3.
d Complete the trace table when the input is 4.

Line Variable Condition Condition Condition Condition Output


food food == 1 food == 2 food == 3 else

2 Discuss with your partner the error that the trace table has
helped to identify.
3 Edit the Python program to correct the error, and save it as
FoodSelectionChatbotV2.py.
4 Repeat the trace table to check that the program now works
correctly.
5 Annotate your trace table to identify where the integer and
Boolean data types are used.
6 Discuss with your partner how you can use trace tables
as you use iterative development to create your software
prototype.

Error processing
Learn
In the previous section, you learned about trace tables and how they can be used to check
algorithms and Python program prototypes. This is a useful process to follow to identify
errors and fix them.
The main focus of iterative development is to produce a fully working prototype and
then a finished solution that is free from error. If a chatbot is released that has not been
thoroughly tested, it may not work properly and this would mean that it is not able to ask

23
369825_9.1_Cam_LSC_SB_008-054.indd Page 24 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

the necessary questions to help the user to find a solution. As a program is developed, a
series of processes are followed to find and fix errors, for example, using trace tables.
Errors that are introduced at the design stage can filter through to the development
stage if they are not identified early on. This could result in the product needing to be
redeveloped, which could be very costly and would take extra time. Therefore, it is
important to find and fix any errors as early as possible in the process.
Errors can be categorised in three ways:
● Logic errors: The program will run but does not output what is expected; an example
of a logic error is the inclusion of an incorrect conditional operator.
● Syntax errors: Errors in the program code that stop the program from running;
an example of a syntax error is where the code has been typed incorrectly, for
instance, missing brackets, colons or indentation or incorrect spelling, to name
a few.
● Runtime errors: Errors that occur while the program is running as the instructions
cannot be completed; an example of a runtime error is where the variable name has not
been added correctly in one aspect of the program – it would not generate an error
until it is used.
Testing an algorithm before it is developed into the program code can help to find and fix
any errors early on.
In the previous section, you looked at trace tables. Trace tables can also be used to find
any logic errors in an algorithm. A logic error does not stop the program from running,
but the program doesn’t do what you expect it to.
One area that can cause a logic error is the use of conditional operators in conditional
statements.
KEYWORDS
Here’s a reminder logic error: error that allows a
of the conditional program to run but not output what
operators. is expected
syntax error: error in program code
that stops the program from running
Conditional operator Description runtime error: error that occurs while
a program is running; the instructions
== equal to cannot be completed
!= not equal to conditional operator: symbol,
> greater than e.g. >, < and =, used to carry out
comparisons between two values
>= greater than or equal to
conditional statement: completes a
< less than check to see whether set criteria is
<= less than or equal to either True or False

If these operators are used incorrectly, the outcome of comparisons could be wrong,
and this would result in the wrong output from the program. For example, if a chatbot
asks for a value to be added, then the correct value needs to be detected in the
comparison if food == 1.

24
369825_9.1_Cam_LSC_SB_008-054.indd Page 25 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Look at the example below of an algorithm (presented as pseudocode) and a trace table
to find and fix the logic error. The pseudocode has been developed as a plan for a chatbot
program to allow a student to enter their score and output the level they are working at,
along with a message of encouragement.
1 START
2 OUTPUT "Student score chatbot"
3 score = INPUT "Enter your recent score."
4 IF score > 90 THEN
5  OUTPUT "You are working at a Distinction level."
6  OUTPUT "Keep the focus on new subject areas."
7 ELSEIF score >= 51 AND <= 89 THEN
8  OUTPUT "You are working at a Merit level."
9  OUTPUT "You are doing well. Focus on revision techniques."
10 ELSEIF score >= 20 AND <= 50 THEN
11  OUTPUT "You are working at a Pass level."
12  OUTPUT "Some extra sessions may help improve your understanding."
13 ELSE
14  OUTPUT "You have not passed this assessment."
15  OUTPUT "Some one-to-one time would help with looking at content."
16 ENDIF
17 STOP

In the same way as you would test program code with a test plan and a range of data
inputs, you need to use a range of inputs to test the algorithm. Each input will require
a new trace table.
Test 1: Trace table for input of score 10

Line Variable Condition Condition Condition Condition Output


Score score > 90 score >= 51 score >= 20 else
and <= 89 and <= 50
3 10
4 False
7 False
10 False
13 True
14 You have not
passed this
assessment.
15 Some one-to-one
time would help
with looking at
content.

25
369825_9.1_Cam_LSC_SB_008-054.indd Page 26 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The trace table shows that when a score of 10 is entered, the conditions on lines
4, 7 and 10 are all False. The program moves to the else section and generates an
output of ‘You have not passed this assessment.’ and ‘Some one-to-one time would help
with looking at content.’ The trace table shows that the algorithm works correctly for
this value.
Test 2: Trace table for input of score 20

Line Variable Condition Condition Condition Condition Output


score score > 90 score >= 51 score >= 20 else
and <= 89 and <= 50
3 20
4 False
7 False
10 True
11 You are working at a Pass
level.
12 Some extra sessions
may help improve your
understanding.

The trace table shows that when a score of 20 is entered, the conditions on lines 4 and
7 are both False. The condition on line 10 is True and generates an output of ‘You are
working at a Pass level.’ and ‘Some extra sessions may help improve your understanding.’
The trace table shows that the algorithm also works correctly for this value.
Test 3: Trace table for input of score 89

Line Variable Condition Condition Condition Condition Output


score score > 90 score >= 51 score >= 20 else
and <= 89 and <= 50
3 89
4 False
7 True
8 You are working at a Merit
level.
9 You are doing well. Focus
on revision techniques.

The trace table shows that when a score of 89 is entered, the condition on line 4 is False.
The condition on line 7 is True and generates an output of ‘You are working at a Merit
level.’ and ‘You are doing well. Focus on revision techniques.’ The trace table shows that
the algorithm also works correctly for this value.

26
369825_9.1_Cam_LSC_SB_008-054.indd Page 27 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Test 4: Trace table for input of score 90

Line Variable Condition Condition Condition Condition Output


score score > 90 score >= 51 score >= 20 else
and <= 89 and <= 50
3 90
4 False
7 False
10 False
13 True
14 You have not passed this
assessment.
15 Some one-to-one time
would help with looking at
content.

When a score of 90 is input, the expected output would be for the student to receive the
level of Distinction. However, from tracking the variable in the trace table, you can see that
the condition is not producing the correct outcome. This is a logic error. The conditional
operator has been set as greater than ( > ) when it should be set as greater than or equal
to ( >= ).
1 START
2 OUTPUT "Student score chatbot"
3 score = INPUT "Enter your recent score."
4 IF score >= 90 THEN
5 OUTPUT "You are working at a Distinction level."
6 OUTPUT "Keep the focus on new subject areas."
7 ELSEIF score >= 51 AND <= 89 THEN
8 OUTPUT "You are working at a Merit level."
9 OUTPUT "You are doing well. Focus on revision techniques."
10 ELSEIF score >= 20 AND <= 50 THEN
11 OUTPUT "You are working at a Pass level."
12 OUTPUT "Some extra sessions may help improve your understanding."
13 ELSE
14 OUTPUT "You have not passed this assessment."
15 OUTPUT "Some one-to-one time would help with looking at content."
16 ENDIF
17 STOP

If this error had not be found at this stage, the wrong operator would have been used in
the program code and the error would not have been spotted until much further through
the process. If you are using conditions that involve comparisons, it is important to test
the algorithm using a wide range of data inputs. In this example, some specific numbers
were used in the dry-run testing, but it would be better to test each value that is used in a
conditional statement and a selection of other values in between.

27
369825_9.1_Cam_LSC_SB_008-054.indd Page 28 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Open the file StudentScoreChatbot.py provided by your
teacher.
a Run the program to find the syntax error.
b Correct the program and save it as
StudentScoreChatbotV2.py.
2 Create trace tables for the following inputs:
a 95 b 15 c 25 d 80
3 a Annotate the trace table to identify where the logic error is.
b Correct the program and save it as
StudentScoreChatbotV3.py.
4 a Discuss with your partner how trace tables helped to
identify the logic compared with how you identified the
syntax error.
b Evaluate how effective a trace table can be to identify
errors and help development.

Iteration introduction
Learn
So far, you have created Python programs
using two programming constructs: sequence
and selection. Remember: sequence is the order
in which the program code needs to be
Another programming construct is iteration. to work correctly; selection allows a choice
You have seen that iteration in program to be added to the program using if…
development is about repeating a series of elif… else so that the next instruction
steps to develop the program continuously executed in the program is decided by
until the final solution is reached. In the outcome of a condition.
programming, iteration is a set of instructions
that are repeated, and it is also referred to as
a loop.
A count-controlled loop is where a series of program instructions is repeated a set
number of times. This type of loop is also called a for loop.
Here’s an example of a for loop:

28
369825_9.1_Cam_LSC_SB_008-054.indd Page 29 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

The structure of a for loop is important:


● for tells the computer that it will be running a for loop.
● i is a variable that is used to count how many times the code in the loop has been
repeated; it starts at 0 and increases by 1 each time the loop has finished running –
the variable ‘i’ is often used as it is short for ‘iteration’, but you can use any variable
name of your choice here.
● in is used to separate the variable from the number of times the loop will run.
● range(5) defines the number of times the loop will run.
● : is used to signal the beginning of the code that will be repeated.

All the lines of code that need to be repeated when the loop runs are indented
underneath, in the same way that code is indented after if, elif and else.
● print("This is loop," i) outputs the text ‘This is loop’ followed by the value
stored in the variable ‘i’ to show the iteration that the program is on.
Program output
When the program above is run, the output displayed would be:

The loop variable always starts at 0 and the loop is executed until the value of
the loop variable is the same as the number in the brackets after range(). In
the example above, to output the number 5 the range would need to be increased
to 6.

A chatbot may need to ask the same set of questions more than once. You can use a for
loop to set the number of times a question is asked and test the input using selection. It is
important that the conditional statements are indented inside the for loop.
In the pseudocode below, the program outputting the iteration number is developed to
check the value stored in the variable ‘i’. If the value of i is greater than 3, then the output
is ‘This is loop’, the value of i and ‘Iterations complete’. If the value of i is 0, 1, 2 or 3, then
the output is ‘This is loop’ and the value of i. In pseudocode, the actual values of the count
variable are stated.

29
369825_9.1_Cam_LSC_SB_008-054.indd Page 30 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

START
FOR i = 0 TO 4
IF i > 3 THEN
OUTPUT "This is loop",i,"Iterations complete"
ELSE
OUTPUT "This is loop",i
ENDIF
ENDFOR
STOP

It is important that the selection statements are indented inside the for loop. The output if
the conditional statement is True or False is indented under the IF and ELSE sections.
This pseudocode can be developed into a Python program, ensuring that the same
indentation is used.

KEYWORDS
sequence: order that program code needs to be in to work correctly
selection: choice to be added to a program using if… elif… else and the
next instruction executed in the program is decided by the outcome of a
condition
execute: carry out the instructions described in a computer program
iterate/iterative/iteration: repeat/repeated/repetition
count-controlled loop: set of instructions repeated a set number of times
for loop: the Python or MicroPython loop for a count-controlled loop
loop variable: variable that counts the number of times code has been
repeated in a count-controlled loop

Practise
Open your file FoodSelectionChatbotV2.py from the earlier
section ‘Code tracers’.
1 Discuss with your partner how a count-controlled loop could
be added to allow the question and selection program code to
be run twice.
2 Edit the program code to include a for loop. Save your new
program development as FoodSelectionChatbotV3.py.

30
369825_9.1_Cam_LSC_SB_008-054.indd Page 31 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Iteration in algorithms
Learn
Using a loop can avoid the need to rewrite lines of program code multiple times. Look at
the two flowcharts below. Compare them to identify their similarities and contrast them to
identify the differences between them.

Flowchart 1 Flowchart 2

Start Start

favSubject1 = INPUT i=0


"What is one of your
favourite subjects?"

OUTPUT favSubject1 No
Stop if i < 3

Yes
favSubject2 = INPUT
"What is one of your
favourite subjects?" favSubject = INPUT
"What is one of your
favourite subjects?"

OUTPUT favSubject2
OUTPUT
favSubject

favSubject3 = INPUT
"What is one of your
favourite subjects?"
i=i+1

OUTPUT favSubject3

Stop

Flowchart 1 will: Flowchart 2 will:


● ask the user to enter one of their favourite subjects ● set a variable ‘i’ to 0
and then output the subject ● check whether ‘i’ is less than 3
● ask the user to enter one of their favourite subjects ● if it is less than 3, ask the user to enter one of their
and then output the subject favourite subjects and then output the subject
● ask the user to enter one of their favourite subjects ● increase ‘i’ by 1
and then output the subject ● loop round to check whether ‘i’ is less than 3
● stop. ● continue the loop until the value stored in ‘i’ is not
less than 3; then the program will stop.

31
369825_9.1_Cam_LSC_SB_008-054.indd Page 32 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Both flowcharts have asked the user to enter their favourite subject and output what it is
three times. However, the use of a loop in flowchart 2 makes the algorithm more efficient.
The efficiency of a program is measured by how long it takes to run. Usually, if the code
can be written in fewer lines, it is more efficient.
You can use the flowchart to create pseudocode to represent the same algorithm.
Flowchart 1
Each shape of the flowchart is represented on a single line in pseudocode. Remember to
capitalise the words INPUT and OUTPUT and define the START and STOP.

Flowchart Pseudocode
1 START
Start
2 favSubject1 = INPUT "What is one of your favourite subjects?"
3 OUTPUT favSubject1
4 favSubject2 = INPUT "What is one of your favourite subjects?"
favSubject1 = INPUT
"What is one of your 5 OUTPUT favSubject2
favourite subjects?" 6 favSubject3 = INPUT "What is one of your favourite subjects?"
7 OUTPUT favSubject3
8 STOP

OUTPUT favSubject1

favSubject2 = INPUT
"What is one of your
favourite subjects?"

OUTPUT favSubject2

favSubject3 = INPUT
"What is one of your
favourite subjects?"

OUTPUT favSubject3

Stop

32
369825_9.1_Cam_LSC_SB_008-054.indd Page 33 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Flowchart 2
The for loop in pseudocode is defined using the starting value of the variable ‘i’ and the
value that it needs to count to. The end of the for loop is shown using ENDFOR.

Flowchart Pseudocode
START
Start
FOR i = 0 TO 2
favSubject = INPUT "What is one of
your favourite subjects?"
i=0
OUTPUT favSubject
ENDFOR
STOP

No
Stop if i < 3

Yes

favSubject = INPUT
"What is one of your
favourite subjects?"

OUTPUT
favSubject

i=i+1

The use of a loop can make the flowchart seem more complicated. However, the use of a
loop means that less code is going to be needed and makes the algorithm easier to follow.
You can take the pseudocode and use this to create the program in Python.

Pseudocode Python code


FOR i = 0 TO 2

favSubject = INPUT
"What is one of
your favourite
subjects?"
OUTPUT favSubject

The program code is written using three lines of code. If you wrote this without using a
for loop, it would require six lines of code. You can see this in the comparison below. The
program with the count-controlled loop (for loop) is more efficient.

33
369825_9.1_Cam_LSC_SB_008-054.indd Page 34 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Program with a
for loop

Program without
a for loop

KEYWORD
efficient: the efficiency of a program can be measured by how quickly
it runs

Practise

Pseudocode 1 Pseudocode 2
1 START 1 START
2 import time library 2 import time library
3 3
4 countdown = 3 4 countdown = 4
5 OUTPUT countdown 5 FOR i = 0 to 2
6 countdown = countdown – 1 6 OUTPUT countdown – 1
7 wait 1 second 7 wait 1 second
8 OUTPUT countdown 8 ENDFOR
9 countdown = countdown – 1 9 OUTPUT "Let’s start"
10 wait 1 second 10 STOP
11 OUTPUT countdown
12 wait 1 second
13 OUTPUT "Let’s start"
14 STOP

1 Follow the pseudocode above and predict with your partner


what each program is designed to do.
2 Discuss how a countdown could be used at the start of a
chatbot.
3 Compare and contrast the two algorithms with your partner.
Copy and complete the table below to identify the similarities
and differences between the two algorithms.

Similarities Differences

34
369825_9.1_Cam_LSC_SB_008-054.indd Page 35 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

4 Decide which algorithm on the previous page is more efficient


and explain why.
5 For pseudocode 2, using the count-controlled loop,
complete the following variable and data type table.

Variable Data type

6 Use pseudocode 2 to create the Python program


using a count-controlled loop. Save the file as
CountdownChatbotStart.py.
7 Complete the trace table using the Python program.

Line Variable Variable Output


i countdown

8 Discuss with your partner how a count-controlled loop could


be used to create a loading-style beginning to a program or a
countdown to the start of a chatbot.

Iterations and arrays


Learn
In the previous program you looked at, a for loop was used to output the same question
three times, which reduced the amount of code needed. However, the program doesn’t
store all three answers in separate variables. Instead, each input from the user overwrites
the content of the variable ‘favSubject’. This is fine if the user needs just to see the output
to their question, but what if you want to store and use the answers again?
A solution to this is to use an array. An array is a data structure that can store more than
one item of data under a single identifier. In most programming languages, an array holds
just one type of data, such as strings. However, Python uses lists that can include items of
any data type.
A Python list is defined in a similar way to a variable. You give the list a name followed by
an equals sign ( = ), and then square brackets ( [ ] ) are used to show the start and end of
the data items.
Look at this shopping-list array with three items: bread, milk and apples.

35
369825_9.1_Cam_LSC_SB_008-054.indd Page 36 09/03/23 8:38 AM A4902 /Data%20Disk/Manoj%20R/2023/March/09-03-23/HO02737_142

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Each item has quotation marks around it as they are all strings. This is the same as you
would use on an individual string being stored in a variable. The items in the list are
separated by commas.
Once you have created a list, there are various ways in which you can manipulate the
contents. The append() method is used to add an item to the end of a list. A full stop and
append() are added to the list name, and the item to be added is put inside the brackets.
In the example below, append() is used to add grapes to the list.

When the program is run, the print command outputs the contents of the list on one line,
including the square brackets and quotation marks.

To improve the presentation of the output, you can use a for loop to display each item
of the list on a separate line. This will also remove the square brackets, commas and
quotation marks.
Instead of using ‘i’ as the variable, you can use a more specific variable name. The
example below uses ‘item’, as each item in the shopping list will be printed.

The output is now in a vertical list with just the items showing.

The len() function can be used to find out how many items are in a list. In the
program below, the value is stored in a variable called ‘num’.

It can be used in an output to say how many values are in the list.

36
369825_9.1_Cam_LSC_SB_008-054.indd Page 37 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Look again at the chatbot program from the previous section that asks the user three
times what their favourite subject is and stores their answers. An empty list called
‘favSubjects’ can be set up at the start of the program:

A for loop can be set up to run


three times: Remember: A count-
controlled loop is set to run
the indented code a set
number of times. In Python,
On each iteration, the program
this is a for loop.
needs to ask the user what one
of their favourite subjects is and
then add their answer to the list. This can be done
in a single line of code, indented below the code to run the loop:

A second for loop can be used to print out the subjects:

The program now makes use of an array and two for loops to get the inputs from the user,
store them and then output them.

KEYWORDS
array: data structure in a program that can store more than one item of data
of the same data type under a single identifier; data items can be changed
list: data structure that stores multiple items of data in a single variable; the
values can be changed
data item: piece of information that represents part of the data that makes
up a person, place or thing, e.g. some of the data items that represent a
person are their first name and second name

Practise
A chatbot has been created to use an array to store a range of
colours that a user enters.
START
ARRAY rainbow = [red, orange]

FOR i = 0 TO 4
Add INPUT to ARRAY "Add a colour"
ENDFOR

37
369825_9.1_Cam_LSC_SB_008-054.indd Page 38 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

OUTPUT " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "


OUTPUT "Your rainbow colours are:"

FOR each colour in ARRAY rainbow:


OUTPUT colour
ENDFOR
STOP
1 Look at the pseudocode and discuss these questions with
your partner.
a What is the content of the array at the start of the
program?
b How many times will the user be asked to enter a colour?
c What will the output be at the end of the program?
d What is the purpose of the dashed line?
e What will be the content of the array at the end of the
program when you add the colours: yellow, green, blue,
indigo and violet?
2 Predict the expected output at the end of the program.
3 Use the pseudocode to create the Python program code for
the chatbot, and save it as rainbowColoursChatbotV1.py.
4 Discuss with your partner whether your output prediction was
correct.
5 Discuss with your partner the purpose of the array in this
program and how the program accesses the data stored in the
array.

Developing the chatbot further


Learn
You have used all the key programming concepts across this and previous stages:
sequence, selection and iteration.
Chatbot programs need to use selection to allow the user’s answer to determine the
next step in the program. For example, the user could be asked questions about the
sort of activity they prefer to do, and the chatbot could suggest a new activity for them
to try.
Look at this example, which shows how a chatbot would use questioning to narrow down
the possible options and aid the decision-making process.
Program development iteration 1
First, the algorithm is planned using either a flowchart or pseudocode. The algorithm uses
sequence, selection and iteration.

38
369825_9.1_Cam_LSC_SB_008-054.indd Page 39 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Flowchart:
Start

ARRAY water =
"Swimming",
"Canoeing"

ARRAY team =
"Hockey",
"Volleyball"

OUTPUT "Do you


prefer watersports
or team games?"

INPUT
typeOfActivity

if typeOfActivity No
== "W"

Yes

OUTPUT "Which OUTPUT "Which of


of the following the following team
watersports do games do you
you prefer?" prefer?"

i=0 i=0

INPUT No No INPUT
if i < 2 if i < 2
activity1 activity2

Yes Yes

OUTPUT OUTPUT
OUTPUT OUTPUT
"You have chosen" "You have chosen"
i + 1, water[i] i + 1, team[i]
activity1 activity2

i=i+1 i=i+1

Stop

39
369825_9.1_Cam_LSC_SB_008-054.indd Page 40 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Pseudocode:
START
ARRAY water = [Swimming, Canoeing]
ARRAY team = [Hockey, Volleyball]
OUTPUT "Do you prefer watersports or team games?"
INPUT typeOfActivity

IF typeOfActivity == "W" THEN


OUTPUT "Which of the following watersports do you prefer?"
FOR i = 0 to 1
OUTPUT i + 1, water[i]
OUTPUT "Enter the number of your preferred activity."
INPUT activity1
OUTPUT "You have chosen" activity1

ELSE
OUTPUT "Which of the following team games do you prefer?"
FOR i = 0 to 1
OUTPUT i + 1, team[i]
OUTPUT "Enter the number of your preferred activity."
INPUT activity2
OUTPUT "You have chosen" activity2

ENDIF
STOP

Next, the program code is developed to match the algorithm.


The program:
● asks the user whether they prefer watersports or team games
● outputs a question asking the user to select which activity they prefer
● saves their choice in a variable called ‘typeOfActivity’.

If the item stored in the variable ‘typeOfActivity’ is "W", then the chatbot displays a list of
water activities stored in an array called ‘water’.
The program then:
● outputs a question asking the user to select which of the water activities they prefer,
and saves their choice in a variable called ‘activity1’
● confirms their choice in an output.

Else the chatbot displays a list of team games stored in an array called ‘team’.
Then the program:
● outputs a question asking the user to select which of the team games they prefer, and
saves their choice in a variable called ‘activity2’
● confirms their choice in an output.

40
369825_9.1_Cam_LSC_SB_008-054.indd Page 41 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

The program code matches the algorithm using variables, selection and iteration in a
Python program.

If the program is developed to ask the user to choose between three types of activity,
then an additional comparison will be needed. This will mean adding elif to the algorithm
and program.
Program development iteration 2
A new iteration of the algorithm is planned to refine the chatbot further by using the value
stored in ‘activity1’ or ‘activity2’ to suggest an alternative activity that the user might like
to try.

41
369825_9.1_Cam_LSC_SB_008-054.indd Page 42 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Flowchart
Start

ARRAY water =
"Swimming",
"Canoeing"

ARRAY team =
"Hockey",
"Volleyball"

OUTPUT "Do you


prefer watersports
or team games?"

INPUT
typeOfActivity

if typeOfActivity No
== "W"

Yes

OUTPUT "Which OUTPUT "Which of


of the following the following team
watersports do games do you
you prefer?" prefer?"

i=0 i=0

INPUT No No INPUT
if i < 2 if i < 2
activity1 activity2

Yes Yes

OUTPUT OUTPUT "You


OUTPUT OUTPUT
"You have chosen" have chosen"
i + 1, water[i] i + 1, team[i]
activity1 activity2

ARRAY waterNew = ARRAY teamNew =


"Waterpolo", i=i+1 i=i+1 "Cricket","Beach
"Sailing" volleyball"

No No
if activity1 == 1 if activity2 == 1

Yes Yes

OUTPUT OUTPUT OUTPUT OUTPUT


"Why not try" "Why not try" "Why not try" "Why not try"
waterNew[0] waterNew[1] teamNew[1] teamNew[0]

Stop

42
369825_9.1_Cam_LSC_SB_008-054.indd Page 43 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Pseudocode
START
ARRAY water = [Swimming, Canoeing]
ARRAY team = [Hockey, Volleyball]
ARRAY waterNew = [Water polo, Sailing]
ARRAY teamNew = [Cricket, Beach volleyball]
OUTPUT "Do you prefer watersports or team games?"
INPUT typeOfActivity

IF typeOfActivity == "W" THEN


OUTPUT "Which of the following watersports do you prefer?"
FOR i = 0 to 1
OUTPUT i + 1, water[i]
OUTPUT "Enter the number of your preferred activity."
INPUT activity1
OUTPUT "You have chosen" activity1
IF activity1 == 1 THEN
OUTPUT "Why not try" waterNew[0]
ELSE
OUTPUT "Why not try" waterNew[1]
END IF

ELSE
OUTPUT "Which of the following team games do you prefer?"
FOR i = 0 to 1
OUTPUT i + 1, team[i]
OUTPUT "Enter the number of your preferred activity."
INPUT activity2
OUTPUT "You have chosen" activity2
IF activity2 == 2 THEN
OUTPUT "Why not try" teamNew[0]
ELSE
OUTPUT "Why not try" teamNew[1]
END IF

END IF
STOP

Then the program code is developed to match the algorithm.


The program uses the value of the variable ‘activity1’ or ‘activity2’ to output the name of
the activity that the user might like to try.
The program code has now been developed to use the answer from one question to
decide which question to ask next, and then uses the answer from the second question to

43
369825_9.1_Cam_LSC_SB_008-054.indd Page 44 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

advise the user which activity they might like to try. The program uses several variables,
conditional statements and count-controlled loops to allow different pathways through
the chatbot program. Note that the extra arrays have been set up at the start of the
program so that they can be accessed easily at any point when the program is run.

This program has now gone through two development iterations.

Practise
As a chatbot program is developed, the different concepts are
integrated. For example, if you need a conditional statement to
check what the user enters, then you need to use selection. If
you want to run program code for a set number of times, then
you need to use a count-controlled loop.
1 Discuss with your partner how this program could be
developed to include additional activities for the user to
choose between.
2 Plan a new iteration of the chatbot algorithm that asks the
user to choose from three different watersports or team
games and gives a suggestion for a new activity to try for
each activity chosen. Do this as pseudocode.

44
369825_9.1_Cam_LSC_SB_008-054.indd Page 45 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

3 Compare and contrast your pseudocode development with KEYWORD


your partner. Test each other’s algorithm using a trace table, one-dimensional
array: series of items
fixing any errors that you identify. grouped together
4 Open ActivitiesChatbot.py provided by your teacher. Develop under one identifier
the program code in Python to create a software prototype to
match your pseudocode, and save it as ActivitiesChatbotV2.
py.
5 Discuss with your partner:
a how using a selection allows you to have different pathways
through your program
b the purpose of the one-dimensional arrays in this chatbot
program.

Testing times
Learn
As you already know, it is particularly important to test the programs that you write to
make sure that they run and that they produce the correct outputs. This is an important
process in developing a new prototype.
To recap, there are different types of errors that can be found when creating programs:
● Syntax
● Logic
● Runtime.

If a program contains a syntax error, it will not run. A syntax error occurs where the
programmer has written the code incorrectly. Possible syntax errors include a missing
bracket, a missing colon or missing indentation.
The program below is a chatbot to guide a user on what to do at the weekend. It contains
a syntax error on line 3 as the colon ( : ) is missing from the end of the line.

45
369825_9.1_Cam_LSC_SB_008-054.indd Page 46 06/03/23 9:46 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The error is detected as soon as the program is run, and an error message is produced.
Different integrated development environments (IDEs) present the error message in
different ways. For example, in IDLE the place where the program has failed is highlighted
and a pop-up suggests what the problem may be:

In a different IDE, the following error message is produced:

Both error messages give a hint to the location and an indication of what type of error has
been encountered.
As you saw with trace tables, a logic error is linked to the conditional operator that is used. The
program will run but the output will not be as expected if the wrong operator has been used.
A runtime error occurs during the running of a program when Python cannot execute an
instruction. For example, look at this program code for the chatbot program to select a
possible activity for the weekend.
Program
code

When
executed

46
369825_9.1_Cam_LSC_SB_008-054.indd Page 47 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

The first part of the program runs correctly, but the program encounters a problem at
line 9. The program output stops and a traceback message is displayed that helps to
identify where the error occurred. Here, ‘activity’ has been used in the for loop instead of
‘activities’ for the name of the array.
Finding and fixing errors is an important part of a programmer’s role, as all aspects of a
program need to work correctly.
When you test a program, you should use a range of test data to check that the program
runs as expected. However, a programmer cannot test every possible input a user might
add to a program, so they must decide carefully which data to use when they create their
test plan.
Look at a chatbot program that asks the user to guess a number between 1 and 10.

There are three possible types of test data that should be used in a test plan for this
program.
● Normal data: A sensible input that the program should accept: any number between
1 and 10.
● Extreme data: Still an acceptable input but at the ends of the possible input range:
using 1 or 10 as the input.
● Invalid data: An input that should not be accepted: using a value outside the
acceptable range, such as 20.
These values can be added to a test plan and then used to test the program. This test plan
has been completed for the program above using a range of test data:

Test Test data Expected outcome Pass/fail


Normal 5 Not correct Pass
Normal 6 You guessed correctly! Pass
Extreme 1 Not correct Pass
Extreme 10 Not a valid guess Fail
Invalid 20 Not a valid guess Pass

47
369825_9.1_Cam_LSC_SB_008-054.indd Page 48 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The test plan has shown that the program ran all the way from start to finish. This shows
that there are no syntax errors or runtime errors. However, one of the tests did fail. The
extreme test data used the input 10, which should produce the output ‘Not correct’, but
instead the output was ‘Not a valid guess’. This shows that a logic error has been found.

Checking the conditional operator used in the elif


conditional statement shows that it has been set as less
than 10 (< 10). To include 10, the conditional operator needs
to be amended to be less than or equal to 10 (<= 10). Once
this has been changed, the programmer should test the
program again to ensure that it now works correctly.

KEYWORDS
syntax error: error in program code that stops the program from running
integrated development environment (IDE): software that includes all the tools
needed to develop a program in a particular language
logic error: error that allows a program to run but not output what is expected
conditional operator: symbol, e.g. >, < and =, used to carry out comparisons
between two values
runtime error: error that occurs while a program is running; the instructions
cannot be completed
traceback message: displayed when a runtime error is encountered to help
identify where the error occurred and what went wrong
normal test data: data of the correct type that should be accepted by a program
extreme test data: acceptable input but at the ends of the possible input range
invalid test data: data that should be rejected by a program

Practise
1 Open the file TestProgram.py provided by your teacher.
a Discuss with your partner what normal, extreme and invalid data you would use to
test this program.
b Create a test plan that uses normal, extreme and invalid test data.
c Complete the test plan.
d Identify and fix the syntax, runtime and logic errors in the code.
e Save the corrected file as TestProgramV2.py.
f Test the program again to make sure that it works correctly.
2 Discuss with your partner the benefits of using normal, extreme and/or invalid test
data for a program’s development.
3 Discuss with your partner the different types of program errors and how a
programmer can find each one.
4 Evaluate in pairs the importance of using a range of test data as a process in program
development.

48
369825_9.1_Cam_LSC_SB_008-054.indd Page 49 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Go further
When a user inputs into a program an answer to a question, the answer is either stored
in a variable or added to an array. The input is stored exactly as the user types it. A user
may input their answer using uppercase or lowercase or a mix of both.
If you are using a conditional statement to compare two variables, the way the user
enters their answer may affect the outcome.
In the chatbot program below, the user is asked to enter a possible activity for the
weekend.

The conditional statement is looking for ‘swimming’ as the input. If swimming was added
using uppercase letters or with an uppercase letter at the start, then the program would
not recognise it as a True outcome as the string would not be an exact match.
As the input is being stored as a string data type, string manipulation can be used to
adjust aspects of the stored string. For, example, no matter how the user enters their
answer, the whole input can be converted to lowercase letters by adding .lower() to
the end of the input. This is useful in a chatbot program where you need to test the input
using selection or need all items in an array to have the same format.

Likewise, the input can be converted to uppercase letters by adding .upper() to the end
of the input.

It is also possible to convert the first letter of a string to uppercase and the rest of the
string to lowercase by adding .capitalize() to the end of the input.

String-manipulation code can also be used to output the length of the string, for
example, the length of the word being stored in a variable.

Or it can be used to find out the length of the array, that is, the number of items being
stored in the array.

49
369825_9.1_Cam_LSC_SB_008-054.indd Page 50 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

In pseudocode, this would be written by defining the way the input should be entered.
START
activity = INPUT lowercase "Enter a possible activity."

IF activity == "swimming" THEN


OUTPUT "A great choice!"
ELSE
OUTPUT "Nice idea, but have you thought about trying swimming?"
ENDIF
STOP
1 Look at the pseudocode you used in the ‘Iterations and arrays’ section.
START
ARRAY rainbow = [red, orange]

FOR i = 0 TO 4
Add INPUT to ARRAY "Add a colour"
ENDFOR

OUTPUT " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "


OUTPUT "Your rainbow colours are:"
Remember that this
FOR each colour in ARRAY rainbow: program has an array to store the
input from the user. The user is asked
OUTPUT colour to enter five colours, as the for loop
iterates five times over the input
ENDFOR
question.
STOP
2 Open your file rainbowColoursChatbotV1.py from the ‘Iterations and arrays’ section.
Discuss with your partner how you think a user would enter their answers when this
program is run.
3 Open the file RainbowColoursChatbot.docx provided by your teacher. Annotate the
pseudocode to show where you could use string manipulation to alter the user’s input.
Add to the algorithm so that it tells the user how many items are in the array after each
new item has been added.
4 Develop your program file so that it matches your new
iteration of the pseudocode algorithm and save it as KEYWORD
rainbowColoursChatbotV2.py. string manipulation:
5 Discuss with your partner how you would test the program process of changing
and identify test data that would be suitable. the format of a
variable/string to
6 Create a test plan with normal, extreme and invalid data and allow it to be analysed
use this to test your rainbow colours chatbot program.

50
369825_9.1_Cam_LSC_SB_008-054.indd Page 51 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

Challenge yourself
You can now add items to an array and use a for loop to access the items. You can have
more than one array in a program and the items can be used multiple times in different
ways. For example, a chatbot may ask you to enter items of clothing you are looking
for and then your favourite colours. This could be used to show you clothes items in the
colours you entered.
Previously, you have used an array in a chatbot program to store three favourite subjects.
In this next iteration of the chatbot, the program is going to ask for the name and
favourite subject of three friends. The chatbot will then output the individual answers.
The pseudocode for the algorithm shows that:
● two empty arrays are set up at the start of the program
● the user is asked three times to enter a friend’s name and their favourite subject
● each name is stored in the array ‘names’
● each subject is stored in another array ‘favSubjects’
● there is an output acting as a separation using dashed lines and a title stating that the
details will follow
● the relevant items from both arrays are located and output in the same sentence.

START
ARRAY names = [ ]
ARRAY favSubjects = [ ]

FOR i = 0 to 2
Add INPUT to ARRAY names "Enter your friend’s name"
Add INPUT to ARRAY favSubjects "Enter their favourite subject"
ENDFOR

OUTPUT " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "


OUTPUT "Your friend’s details are:"
OUTPUT " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "

FOR each item in ARRAY names and ARRAY favSubjects


OUTPUT name "likes" subject
ENDFOR
STOP

To create the final count-controlled loop that looks at both arrays, you need to use
a new function: zip().

The loop needs to look at each item in each array. Two variables can be set at the
start of the for loop to store the item in the list being looked at: for name, subject
in. It is important that the two variables (shown in green here) are separated by a
comma.

51
369825_9.1_Cam_LSC_SB_008-054.indd Page 52 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The two array names are placed inside the brackets of the zip() function, again
separated by a comma. Remember to add the colon at the end of the line to tell
the program that the for loop has been set up: for name, subject in zip(names,
favSubjects):

The output is placed in a print function. The variables defined at the start of the for
loop, to store the items from the arrays, are used in the output.

1 Write a program in Python to match the pseudocode algorithm shown above.


2 Choose suitable test data and develop a test plan to check that your program works
correctly.
3 Save the file as challengeYourself.py.
4 Discuss with your partner the types of test data used in your test plan.

Final project
The skills you have learned in this unit are Part 1: Planning
all about using iterative development to
1 Plan and list the questions that your
produce solutions to problems. You have
chatbot will need to ask. Think about
learned how to trace the variables through
how you might help someone to choose
a program using a trace table and how a
between three different subjects.
count-controlled loop and an array can
2 List the variables and data types that
develop your Python programming further.
are going to be used in your program.
Look back to the start of this unit to 3 Identify suitable names for one or more
remind yourself of the Scenario. arrays to be used in your program. Add
You are going to create a program to help these to your list.
students during the selection of options
Part 2: Develop the algorithm
or subject areas to continue to study.
The chatbot will ask the user a series of 1 Plan the algorithm using pseudocode.
questions, store their answers and use this 2 Annotate your pseudocode to show
to help them to make a final decision. how your program will use an array and
● The solution will be presented as a count-controlled loop.
pseudocode to show the algorithm for 3 Annotate your pseudocode to describe
your chatbot program. the data types that are being used and
● Use variables and/or an array to store which are not being used and why.
the answers to questions asked of the 4 Add a caption to your pseudocode
user. to explain how you will use string
● Use a count-controlled loop. manipulation to adjust a user’s input.
● Follow an iterative process to design, Part 3: Test the algorithm
develop, test and review towards a final
1 Create a trace table and use this
prototype.
to check the contents of variables,

52
369825_9.1_Cam_LSC_SB_008-054.indd Page 53 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

Unit 9.1 Presenting choices: Combining constructs

arrays and the outcome of conditional 4 Use your test plan to test the program
statements in a dry run of the using normal, extreme and invalid data.
pseudocode. 5 Using both the trace table and test
2 Identify suitable test data, including plan, identify any logic, syntax or
normal, extreme and invalid inputs, and runtime errors.
create a test plan to be used on your 6 Save each development as a new
program once it has been written. iteration of the program.
3 If necessary, correct any logic errors
identified by the dry run of your
Part 5: Evaluation of the prototype
program and work through the trace Once you have created, tested and
table again. Ensure that you save any reviewed your prototype program
developments as a new iteration of the solution, evaluate the impact of the
pseudocode. different parts of the process that you
have followed to create your final version
Part 4: Development of the program. Create a short report that
1 When you are sure that the explains:
pseudocode algorithm is complete 1 the iterative process you used to
and correct, start the development of develop your final program code
your Python code. 2 how you used trace tables
2 Continuously test, debug and improve 3 how you used test plans with normal,
your program code. extreme and invalid data
3 Create a trace table and use this 4 the difference between a logic error,
to check the contents of variables, a runtime error and a syntax error
arrays and the outcome of conditional and how you have tested for these
statements as the program is run. throughout the program development.

Evaluation
KEYWORDS
1 Swap programs with your partner and test their program. dry run: process of
Comment on the following: working through an
algorithm manually
a Does it cover all the requirements?
to trace the values of
b Is the solution easy to use? variables
c Do the inputs work as expected? evaluation: checking
d Are the questions suitable for the Scenario at the start of the suitability of a
the unit? solution to a problem

e Are the variables clear to understand?


f What extra features have they added, such as arrays/string
manipulation, and what impact do they have on the final
program?
2 Open your program and look at the code. Reflect on what you
could improve in your own program following feedback from
your partner.
3 Based on the evaluations, make a list of recommendations to
improve your final program.

53
369825_9.1_Cam_LSC_SB_008-054.indd Page 54 06/03/23 9:47 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

What can you do?

Read and review what you can do.


✔ I can follow, understand, edit and correct algorithms that
are presented as pseudocode.
✔ I can follow flowchart or pseudocode algorithms that use
loops.
✔ I can create algorithms using flowcharts and pseudocode.
✔ I can use and explain iteration statements with count-
controlled loops in either pseudocode or flowcharts.
✔ I can predict the outcome of algorithms that use iteration.
✔ I can compare and contrast two algorithms for the same
solution and decide which is best suited to the task.
✔ I can create an algorithm as a flowchart or pseudocode
using more than one construct: sequence, selection and
count-controlled iteration.
✔ I can identify and explain the purpose of a one-dimensional
array.
✔ I can identify and describe data types in Python programs,
including integer, real, character, string and Boolean.
✔ I can develop a Python program with count-controlled
loops.
✔ I can access data from an array using Python.
✔ I can develop Python programs using string manipulation,
including length, uppercase and lowercase.
✔ I can use iterative development on Python prototypes to
create solutions to problems.
✔ I can develop and apply test plans that include normal,
extreme and invalid data.
✔ I can identify test data that covers normal, extreme and
invalid data.
✔ I can identify and describe a range of errors, including
syntax, logic and runtime errors.
✔ I can use a trace table to debug errors in a Python program.

54
369825_9.2_Cam_LSC_SB_055-087.indd Page 55 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit Design your own network:


9.2 Shape and size

Get started!
Have you ever wondered how computer
networks, both big and small, are designed, or
what the boxes full of wires and other devices
that are found in classrooms, offices and homes
across the world actually do? Who decided
where to position them and why did they set up
the network in the way that they did? How do we
make sure that data transmitted across networks
is secure?
Discuss the following with your partner:
l How are devices connected to networks?
l When a device is connected to a network, what type of address is assigned to it?
l Are there ways of knowing whether data has been transmitted accurately?

In this unit, you will develop your understanding of the ways in which networks can be
designed and expanded. You will look at how the design of a network can affect the way
in which devices work on the network. You will investigate how devices communicate and
how data packets are transmitted. Importantly, you will learn how networks can be built
sustainably, so they can be expanded and developed to ensure that they are always fit
for purpose.

KEYWORDS
network: collection of computing devices connected sustainably: when a network is built in a way that it
to each other, either by wires or wirelessly is easy to maintain in the future
data: raw facts and figures fit for purpose: something that is well designed for
data packet: small unit of data that is packaged to its purpose
be sent across a network

Learning outcomes
In this unit, you will learn to:
● explain how different network topologies (bus, ring and star) transfer information
between devices
● explain the role of protocols in data transmission
● explain what scalability factors are and how scalability can affect a network
● explain why scalability should be considered when designing networks and how
networks can be designed to scale up
● explain what a parity bit is and its role in error detection
● perform parity bit and parity block calculations and identify errors in data transmission
● explain the choices that must be made when securing information on a network,
including cost, accessibility and the relative security requirements of different datasets.

55
369825_9.2_Cam_LSC_SB_055-087.indd Page 56 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Warm up
Connecting devices to a network brings a whole range of
possibilities to their use. Some devices simply wouldn’t work
as intended without an active network connection, such as an
internet-connected smart lightbulb or the online services of a
games console.

KEYWORDS
active internet
connection: where a
device has a working
connection to the
internet
high bandwidth:
connection that can
send and receive a
large amount of data
per second
interference:
Discuss the following with your partner: when electronic
signals disrupt data
l What devices do you use that connect to a network? transmissions
l Does the device require an active internet connection to network topology:
work? diagram that
l If the device has an internet connection, does it require a shows how devices
high-bandwidth connection? in a network are
connected to one
l What would happen if the internet connection disconnected another, and shows
due to interference? the network hardware

SCENARIO
A local youth-recreation centre has opened, access to, for example mobile phones, tablets,
with the aim of providing a facility for young gaming consoles, PCs or even smart watches!
people who wish to game, interact and The network should be able to support a large
hang out in a safe, monitored and flexible number of members in the youth centre, with
online environment. The centre has asked users connecting from a range of devices.
the IT department in your school for advice Your challenge is to learn all about network
on networking and security. They also need topologies (network layouts), technologies
advice about the hardware they will need to and the software required to support network
ensure that members can be connected in a communications, before you can advise them
network. The group hopes that students can on their hardware needs for the network.
link up using any electronic device they have

56
369825_9.2_Cam_LSC_SB_055-087.indd Page 57 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

DID YOU KNOW?


The first network to connect different kinds
of computers together was switched on
in October 1969. It was named ARPAnet.
The system was invented to connect large
companies, universities and governments
together so that they could share
information via devices such as teletype
machines.

Do you remember?
Before starting this unit, you should be able to:
✔ decide what type of network should be used in different
scenarios
✔ understand the difference between copper and fibre cables
✔ explain whether wired or wireless networks should be used in
certain scenarios
✔ understand the security features that different types of
networks can have
✔ describe how an echo check can check for data accuracy in
transmission
✔ understand how firewalls, antivirus and anti-spyware can
provide protection to a network
✔ explain the purpose of operating systems
✔ understand what is meant by ASCII.

Building blocks of networking


Learn
People, companies, schools and governments rely on network connectivity to be
dependable and fast. The type of network that is designed by network engineers is crucial
to the network running reliably and speedily. Here’s a recap of the different types of
network.

PANs
Personal Area Networks are a type of network where devices
communicate over a small area, usually no further than
10 metres or so. This type of network is often used for devices
that the user wears, such as headphones or a smart watch.

57
369825_9.2_Cam_LSC_SB_055-087.indd Page 58 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

LANs
Local Area Networks are a type of network where
devices communicate over a small geographical
area. You could think of this as a single building
or a school site, for example. Devices within this
network range are able to access services offered
by the server on the same network, which is ideal
for sharing files, printing or sharing a single internet
connection. In your school network, it is likely that you can access a students’ drive, or
similar, where teachers can place files for you to use.
WANs
Wide Area Networks are a type of network where
devices communicate over larger geographical areas.
An example of this would be a company with a few
offices at opposite sides of town, or even offices in
different countries. These networks usually connect
together via the internet, as it would be physically
impossible to lay dedicated cables between the office
buildings.

WANs rely on external networking equipment, usually Remember that there are
provided via the Internet Service Provider’s (ISP’s) also WPAN, WLAN and WWAN,
cabling, to create a ‘virtual’ link between the LANs of which are the same as PAN,
LAN and WAN but the devices
each office.
connect wirelessly!

KEYWORDS
Personal Area Network (PAN): type of network file storage, user management, printer sharing,
where devices communicate over a small area of no email access or web servers
more than 10 metres, usually connecting devices a Wide Area Network (WAN): type of network
person wears to a smartphone or computer where devices communicate over a large
Local Area Network (LAN): type of network geographical area, such as across a city or country
where devices communicate over a small Internet Service Provider (ISP): company that
geographical area, e.g. a single building provides users access to the internet, and is
server: usually a powerful computer that often responsible for the network equipment
offers a range of services to a network, e.g. that connects LANs to WANs

Network architecture
Network engineers are specialists in building Internet/WAN
networks so that they are fast, dependable and Wi-Fi access
point
safe to use. It is likely that any business, school or Router
government has used a network engineer to help
them to create their network, so that the users can Switch
use it without having problems.
www.africanews.com www.africanews.com www.africanews.com

Laptop Desktop Desktop Desktop

58
369825_9.2_Cam_LSC_SB_055-087.indd Page 59 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Network topologies show how a network is


arranged and how the devices connect to each KEYWORDS
other. Some network topology diagrams can network topology: diagram that shows
how devices in a network are connected
be extremely detailed, to show every aspect
to one another, and shows the network
of a network, including hardware, devices and hardware
connection methods. hardware: physical parts of a computer
The example on the previous page shows a that you can touch and see, e.g. the
processor, storage devices, input devices,
simple network topology diagram connecting
output devices
three desktop computers and one laptop to
router: hardware device that connects
a network. All the devices are connected to a networks together
switch, which forms a LAN. The router then
network switch: switch that connects
joins the LAN to a WAN (the internet). devices together to form a wired network
Imagine you were asked to create a network network interface card (NIC): every
topology diagram for your school that contains device that connects to a network includes
a NIC, which has a pre-programmed MAC
every device and piece of network hardware. It
address so that it can be identified on the
is likely that it would be an exceptionally large network
document! MAC address: number programmed into a
network interface card that identifies each
Network hardware device on a network
When network engineers are designing a wireless access point: allows devices to
network topology, they need to decide what connect to a network using Wi-Fi
network hardware to use to ensure that the
network will be fast, dependable and secure.
The common hardware components of a network are listed in the table below. You will
recognise some of the device names from the basic topology diagram above.

Network switch
Network switches connect devices together on a network to form a wired network.
Router
A router connects together different networks, often connecting a LAN to the
internet.
If you want to send data from one place to another, a router finds the fastest
route to send the data. A router provides access to the internet and sometimes
has wireless access built in, especially in the home.

Network interface card (NIC)


Any device that wants to connect to a network must have a NIC. Network cards
can be wired or wireless and enable the device to access the network.
NICs have a MAC address, which is hard-coded and cannot be changed, to
identify the device on a network.
Wireless access point
A wireless access point is a network device that allows wireless-capable devices
to connect to the network using Wi-Fi.

59
369825_9.2_Cam_LSC_SB_055-087.indd Page 60 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Ethernet cabling
These are cables that are designed to work with ethernet ports on a NIC to
connect devices to a network. They are dependable for high-speed connections,
with a maximum bandwidth of 10 Gbps (gigabits per second). The longer the
cable, the worse the performance.

Servers
Servers are computers on a network that offer a service to other devices. Here are
some common servers found on networks.
File servers: These offer devices on a network a place to store and access files.
On large networks, files are not usually stored on the device that the user is using,
but on the file server. This can be especially useful in a business where a number
of people need to access the same files, or where people may need to access their
files from any computer on the network.
Print servers: These enable devices on a network to share printers. In a large office it
would not be feasible for every device to have its own printer. A print server manages
which devices can print to each printer so that users can share them.
Mail servers: These store email messages and allow users to log in to send and
receive messages.
Web servers: These provide internet-accessible files and transmit files to users
over the world wide web.
Firewall
Most networks, especially business networks, use a hardware firewall. This
examines the incoming and outgoing network traffic to check for security risks
and block any suspicious activity.

You will learn more about how data is sent between the devices on a network later
in this unit.

KEYWORDS
file server: server that stores users’ files and network traffic: amount of data travelling through
enables them to be shared on a network a network, split into small parts for transmission
firewall: restricts the network traffic entering and
exiting a network, to ensure that it is safe

Practise
1 Open the file Network hardware.docx provided by your teacher. Complete the table
without using this book, where possible. Provide a brief summary of each of the
network devices. Copy and paste images from the internet of the devices you find.
2 a Open the file Network uses.docx provided by your teacher. For each of the rows in the
table, explain how the youth centre in the Scenario could use the device in their network.
If you need to remind yourself of the Scenario, look back at the start of this unit.
b Complete the diagram to show the following connections:
i the router to a port on the network switch
ii each of the laptops to the network switch to form a LAN
iii the LAN to the WAN.

60
369825_9.2_Cam_LSC_SB_055-087.indd Page 61 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Topologies and architecture


Learn
You are probably used to using networks at home and at school. This gives you an
excellent oversight of a small LAN (home) compared with a larger LAN (school). Both of
these networks will probably link to the internet (a WAN), and routers are used to join
your home or school network to the internet.
As you explored in the previous section, network topology is how the hardware devices are
arranged and connected in a network. There are some well-known topologies that have been
tried and tested over time. Each of these topologies has advantages and disadvantages.

Bus topology
In a bus topology, all the devices (servers, computers, printers) are joined to one cable
(the bus). There is a terminator at each end of the cable to absorb the signals and stop
them from being reflected back down the bus.

www.africanews.com www.africanews.com www.africanews.com

Desktop Desktop Desktop

Terminator Terminator

www.africanews.com www.africanews.com www.africanews.com

Desktop Desktop Desktop

Advantages Disadvantages
l Bus networks are easy to install. l If the main cable fails or is damaged, the whole network
l They are cheap as they don’t need a lot of will stop working.
cable. l As the network gets larger, it is more likely that data will
collide and be corrupted as it is sent between devices.
This reduces the performance of the network.
l All devices on the network are visible to each other, which
could pose a security risk.

KEYWORDS
router: hardware device that connects networks terminator: ending to a network cable that
together absorbs the signal to stop it bouncing back
network topology: diagram that shows how colliding: when data ‘bumps into’ other data,
devices in a network are connected to one which often causes errors or lost data
another, and shows the network hardware
bus topology: network in which all devices are
connected together via a main cable running
down the centre of the network

61
369825_9.2_Cam_LSC_SB_055-087.indd Page 62 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Ring topology
In a ring topology, each device is connected to two other devices, forming a ring for
the data to travel around. The data travels in one direction and is passed through each
device until it reaches its destination.

www.africanews.com

Desktop
www.africanews.com www.africanews.com

Desktop Desktop

www.africanews.com www.africanews.com

Desktop www.africanews.com
Desktop

Desktop

Advantages Disadvantages
l Data travelling on a ring network flows only one way, which l If the main cable of the ring network is
means that data does not collide. broken, it will stop the entire network
l Data can be transferred quite quickly, even if there are a working for all devices connected to it.
large number of devices connected.

Star topology
In a star topology, every device on the network has its own connection to a switch. The
main switch sends data packets to the destination device only.

Desktop Desktop Desktop

Switch

Desktop Desktop Desktop

62
369825_9.2_Cam_LSC_SB_055-087.indd Page 63 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Advantages Disadvantages
l Each device is connected separately. l If the main switch fails, then none of the devices can
l It is very dependable as the rest of the network communicate.
will continue to work if a cable or device fails. l It can be expensive to install as more ethernet cabling
l Network performance is good as the switch is needed.
directs data to the correct destination.
l It is easy to add new devices to the network, as
they can be attached directly to the switch.

In modern networks, star topologies are usually used, as data collisions do not occur
when a switch is performing its task of directing packets of data to the correct device
only.

When designing networks, it is important to consider what will be the best topology to
use before you start to create the network topology diagram.

Practise
KEYWORDS
1 Look around your classroom. Write a list of all the devices ring topology:
in the room, along with other devices that are used in your network in which
school network. Your teacher will help to identify these. all devices are
connected together
Include how many there are of each device, for example to form a ring
25 PCs, 5 tablets and 15 smartphones.
star topology:
2 Create a network topology diagram for your school. Include: network in which
a a basic icon and label for each of the devices each device is
b any WAPs and switches connected separately
The WAP and/or to a central switch
c lines to show how the devices are
switch may be visible to
connected to a WAP or switch,
you in your classroom
labelled to show whether the or might be in another
device is connected by a wire (W) room nearby.
or wirelessly (WL).
3 Assume that your school has a router, connecting your LAN
to the internet, and a firewall hardware device to improve its
security.
a Add a firewall above the switch, and connect the devices
together.
b Add a router above the firewall, and connect the devices
together.
c Add a WAN/the internet above the router.
d Connect the LAN and WAN together.
4 In groups, discuss the type of network that has been
designed.
a Is it a star, ring or bus network? Why has that type of
network been used?
b What would be the disadvantages of using a ring network
to redesign your school network?

63
369825_9.2_Cam_LSC_SB_055-087.indd Page 64 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

It’s all in the protocol


Learn
Imagine if computer manufacturers created
devices that could communicate only
with other devices made by the same
manufacturer. Smartphones wouldn’t be
able to join cellular networks unless the
mast was made by that manufacturer. PCs
wouldn’t be able to communicate with each
other unless the same company made them.
Network switches would communicate only
with devices that were made by the same
company as the switch manufacturer.
Thankfully, this is where protocols step in to
save the day! Protocols are an agreed set of
rules for communicating over a network. The
protocols used in modern technology allow all kinds of devices to communicate with each
other, regardless of who manufactured them.
There are two main protocols that you need to know about, both of
which have clear rules for how computers should communicate over
a network.
TCP/IP Protocol
Transmission Control Protocol/Internet Protocol (TCP/IP) is a KEYWORDS
collection of rules that govern how computers can communicate protocol: agreed
with each other over a network. set of rules that
computers follow to
When sending data from one device to another on a network, TCP/ communicate with
IP is the protocol used to break the data into packets, address the each other over a
data, transmit the data, route the data and receive any data from network
other devices. Transmission Control
Protocol/Internet
The Transmission Control Protocol (TCP) is responsible for breaking Protocol (TCP/
the data into smaller sections called packets. Imagine that you IP): protocol for
wanted to send an image file from one computer to another. TCP transferring data
between devices
would send part of the image data in each data packet.
data packet: small
Each packet has extremely strict rules about how it should look. unit of data that is
Along with the image data, the TCP protocol adds information to packaged to be sent
each packet, including how many packets there are in total and the across a network
number of each packet. IP address: unique
number assigned
Think of a packet as being like a letter, which needs to include the to a computer on a
address of where the packet is being sent. The Internet Protocol (IP) network
adds the IP address of the sender and the receiver to the packet.
The example below shows a single packet that is ready to be sent
over a network.

64
369825_9.2_Cam_LSC_SB_055-087.indd Page 65 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Sender IP address Receiver IP address Packet number


83.23.55.31 54.211.90.1 5/340
Data
011001101101101111011010110011011011011110110101100110110110111101101011001101101101111011010
110011011011011110110101100110110110111101101011001101101101

Sender IP address: Receiver IP address: This Packet number: This


The packet needs needs to be included in case is included so that the
to include this so of a ‘dropped packet’, which receiving device can re-
that devices on means a packet that did not assemble the packets in
the network know reach its destination. If this is the correct order. It also
where to forward the the case, then the receiver can helps the receiving device
packet to. request that the packet is sent to understand if there are
again. any packets missing.

Packet switching
When data is transmitted across a network, it is split up into small
packets. For example, if somebody wanted to transmit a video file
across a network, the file would be split as follows:

Full video file


Video file packet 1 Video file packet 2 Video file packet 3 Video file packet 4 Video file packet 5

In reality, packets are so small that a video file would likely be split into thousands of
packets.
Packets contain the data that is being sent, and the sender IP address and receiver IP
address, so that the data can be directed to the correct destination.

Video packet 1
Sender IP address 88.34.23.3
Receiver IP address 212.51.22.2
Packet number 5/340
Data 010000101011110110101000101111010110101…

When the packets are assembled, they


are sent across the network. Packets Video
can be sent across the network using Router packet 1 Router
different routes, often travelling through Video
many different devices before they packet 1
Sender
reach their destination. computer
Video
Router
packet 2
Router
The receiving computer will put the
Video
packets in order to check that they have packet 2
Receiver
Router computer
all been received. If there have been Video
Router
any ‘dropped packets’, the receiver will packet 2

re-request that packet and it will be


transmitted across the network again.

65
369825_9.2_Cam_LSC_SB_055-087.indd Page 66 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

HTTP and HTTPS


Hypertext Transfer Protocol (HTTP) and Hypertext Transfer Protocol Secure (HTTPS)
are protocols that exist to allow web browsers to fetch documents from web servers.
Documents could include web pages, text, images or videos. HTTPS is encrypted, which
can prevent unauthorised access if data is intercepted.
Each time a user on a web browser tries to view a document on the world wide web, the
device sends a request to the web server for the information. Here is an example of a
request that is sent when the browser tries to visit www.google.com:

Request headers KEYWORDS


:authority: www.google.com
Hypertext Transfer Protocol (HTTP): set of rules
:method: GET for communicating with web servers
:path: / Hypertext Transfer Protocol Secure (HTTPS): set
:scheme: https of rules for communicating with web servers, with
accept: text/html added encryption to improve security
domain name: part of a URL that specifies the
accept-encoding: gzip, deflate, br
location on the internet, e.g. google.com
accept-language: en-US,en;q=0.9
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0

You will notice that the request includes the domain name, but also includes some
additional information, such as the type of document it is requesting (in this case, html,
which is a webpage document). It also shows what type of web browser the user is using
(Mozilla).

DID YOU KNOW?


The packet-switching concept was invented in the early
1960s by Paul Baran (left, receiving a National Medal of
Technology and Innovation in 2008 from US president
George W. Bush). The concept was designed to send and
receive data successfully even if devices on the network
failed, by redirecting the packets in a different direction from
their destination.

Practise
1 Open the file Protocol.docx provided by your teacher.
a Explain what is meant by a protocol.
b Explain the role of TCP/IP in transmitting data.
c Explain what HTTP and HTTPS are used for.
d Complete the information that needs to be added to the
data packet by the TCP/IP protocol before it can be sent.
e Use your knowledge of data packets to identify which
device should receive each of the data packets shown.
2 Discuss with your partner what is meant by packet switching.

66
369825_9.2_Cam_LSC_SB_055-087.indd Page 67 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Scalable considerations
Learn
Imagine you are a network engineer and have spent a lot of time building the perfect,
fast, reliable and safe network. Everything is running smoothly until your boss asks you
to add another 100 devices to the network! Is it possible to add devices to a network
without changing other aspects of the network? It’s a good question and will need some
investigation.
Network scalability means how well a network can cope if it suddenly needs to move
a lot more data between more devices. If your school opened a new building full of
classrooms, but didn’t upgrade their network hardware, having lots more users on the
same connection would slow down the speed. It could also make the network less secure.
Think about the impact there would be if your school allowed all students to connect their
smartphones to the Wi-Fi. It is important that scalability is considered when a network is
being planned and built.
To assess the scalability of a network accurately, you need to consider the following.

Security
If the network becomes unstable due to a rapid increase in the KEYWORDS
number of devices connected and the amount of data being scalability: capacity
to make something
transmitted, it could cause network hardware to not operate
larger, e.g. a network
properly. For example, if the network were unstable and caused enlarged with more
the firewall to disconnect from the network, the network could devices
be open to the threat of a cyber-attack. cyber-attack:
attempt to gain
It could be an excellent idea to use multiple firewalls. For unauthorised access
example, in a school it might be useful to have a firewall for staff to a network, to
offices and a separate firewall for student computer rooms. This damage or destroy a
way, there is a more limited amount of data flowing through a computer system
single firewall at any time. firewall: restricts
the network traffic
Storage solutions entering and exiting
a network, to ensure
What effect would adding lots more devices have on storing files that it is safe
on the network? If there is a file server, would this need to be
file server: server
expanded, so that the impact of having more users is avoided. that stores users’ files
and enables them
To improve scalability of storage, it would be important to to be shared on a
add either more storage capability to the current file server or network
another file server into the network.
Accessibility of data
If the network is not scalable, then adding more devices that are transmitting a lot of
data around the network could have an impact on the speed of data transmission, as the
bandwidth has to be shared between all the devices. This could also make the network
unstable, causing devices to become disconnected from the network. This may mean

67
369825_9.2_Cam_LSC_SB_055-087.indd Page 68 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

that essential files cannot be accessed


at crucial times. Imagine, for example, if
this happened in a hospital just before a Network administrators are
patient’s operation. often faced with the dilemma of
whether to expand the network
It is important to make sure that the horizontally (adding new devices
network hardware is not overloaded. to the network to increase the
This might mean adding more network scalability) or upgrading the
devices they currently have to
switches, or more wireless access points
improve the capacity of the
for Wi-Fi devices, so that particular
network.
devices are not overused.

Innovation in networking
Cloud computing makes use of servers
on the internet to provide services to
store, manage or process data. Lots of
companies worldwide now use cloud
servers, rather than having their own
servers on their premises. Lots of
smartphone users, for example, use cloud
photo storage, rather than having to
increase the storage available on their device.
Because of the challenges of scalability in networking, new solutions are constantly being
developed. Lots of the most innovative solutions take advantage of cloud computing or
use devices outside the network to do some of the work. For example, if your school were
to open a new building, by using a file server on the internet there would be no reason to
upgrade the file server that is in school. The school would simply pay for an online service
to store staff and student files. Examples of online storage services include Microsoft
OneDrive, Google Drive and Dropbox.
Network system software
Network operating systems (NOS) play an important role in keeping a network running
quickly, reliably and safely. Network operating systems work in the same way as a normal
operating system, but they are designed to be installed on servers. Often, the NOS
manages the users on the network, maintains the network connections, manages file
server features and provides utilities software for keeping the network running well.

An operating system is a piece


of software that manages the
hardware (device drivers) and
software on a computer system.
Commonly used operating
systems are Microsoft Windows,
macOS, iOS, Linux and Android.

68
369825_9.2_Cam_LSC_SB_055-087.indd Page 69 06/03/23 11:09 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Network operating systems also manage resources such as the router, switches and
firewalls.
A common task that the operating system carries out on a network file server is disc
defragmentation. This organises files on a hard disc drive, which can improve the speed
at which files can be accessed on the file server.
User management is essential on a well-maintained network. Network administrators
can control which files, printers, software and other network facilities different types
of user can access. The image on the previous page shows that network administrators
have a number of tools at their disposal to keep the network running well, including file
management. For example, it would not be a good idea to give students access to the
confidential staff folders.
Network utilities software
Utilities software on an NOS works in a similar
way to utilities software on a personal device. Encryption software on
Networks still need to have virus scanning, a network can be extremely
backup and encryption software installed. Instead important, especially if the
of performing this on individual devices, network network holds personal
utilities allow the network administrator to run information about people.
scans, checks and tools on all of the devices on Encryption software can also
the network at the same time. They even allow be used if people connect to the
network remotely, to make sure
network administrators to schedule the tasks to
that the data cannot
run at specific times of the day. For example, in a
be intercepted.
school it would be useful for these to run at 5 a.m.,
before staff and students have arrived.

KEYWORDS
administrator: account with top-level access, with device driver: software program that operates a
the ability to change settings or add and remove hardware device connected to a computer
users from a network defragmentation: reorganising files stored on a
cloud computing: using servers on the internet for hard drive to ensure that all parts of the same file
services are located one after the other on the drive
online storage services: using file storage servers hard disc drive: removable disc in computers for
on the internet to store files storing large amounts of data, typically measured
network operating system (NOS): computer in gigabytes or terabytes
operating system that supports networks, often user management: adding or removing users to
including additional administrator software and control access to a network
monitoring tools virus scanning: checking files on a computer
operating system: software that manages all the system for malicious content
computer hardware and software; it also acts backup: copying files to another location in case
as an interface between computer hardware the original is lost or damaged
components and the user, and provides a platform
encryption: converting information into a
where applications can run
scrambled form, so that it cannot be understood if
utilities software: software that helps maintain the it is intercepted
smooth functioning of a digital device by helping
remotely: connecting to a network from another
the operating system manage tasks and resources
location via an internet connection
software: a program or a set of instructions that
tell a computer what to do to complete a task;
aspects of a device you cannot touch

69
369825_9.2_Cam_LSC_SB_055-087.indd Page 70 10/03/23 10:30 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Open the file Scalability.docx provided by your teacher. Read the scenario.

Ravi is the network administrator for a new company, which has an office. The
company has started selling lots more of their products due to an increase in
demand. They have taken on twelve new employees and need to open another
office in the same building, containing twelve desktop computers.

a Add to the existing network topology diagram of Office 1 to show Ravi how he
could scale up the network.
b Add a comment to the diagram to state the tasks that a network operating system
could carry out on the network.
c Add a paragraph below the diagram to explain what utilities software could be used
to keep the network secure or running more smoothly.
2 Ravi has been asked to remove four computers from Office 1, as they are no longer
needed. Using Scalability.docx, make changes to the network topology diagram of
Office 1 to accommodate the new request.

Internet/WAN

Router

Firewall

Office 1 Office 2

Switch
www.africanews.com www.africanews.com www.africanews.com www.africanews.com

Wi-Fi
Desktop Desktop
access point
www.africanews.com www.africanews.com
Desktop

Desktop

www.africanews.com www.africanews.com

www.africanews.com www.africanews.com

Laptop Laptop Laptop Laptop Laptop Laptop


www.africanews.com www.africanews.com

3 Ravi has designed the network topology, but a year later the network isn’t running
reliably. He investigates the issues and finds that the firewalls he is using are no longer
powerful enough to run a network of this size. Ravi has also noticed that his users are
running out of file storage space, so they are not able to save files on the network. In
the office, he has noticed that the Wi-Fi speeds are very slow, due to the number of
devices trying to access the network.
Explain how Ravi can improve the network, based on the following factors. Write a
paragraph under each heading.
l Security l Storage l Accessibility

70
369825_9.2_Cam_LSC_SB_055-087.indd Page 71 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Checking for errors


Learn
With millions of packets of data transmitted over networks every second, it is to be
expected that some will not reach their destination in one piece. Networks handle so
much data that how devices deal with the errors becomes especially important to the
reliability of a network.

KEYWORDS
data packet: small unit of data that is
packaged to be sent across a network
bit: short for ‘binary digit’: 0 or 1
binary data: data that is represented as a
1 or a 0
hacker: somebody who tries to gain
unauthorised access to a computer
system or network

Electrical spikes or power surges


A power surge is a short burst of significantly
more voltage coming through the electrical wire Remember: the only data
to an electrical device. Power surges can cause that computers understand
binary bits to flip between 0 and 1, causing are 0s or 1s. If one of these
an error in data transmission. They are usually bits is ‘flipped’ then this can
caused by faulty wiring or lightning strikes. cause errors.

Interference
Interference occurs when a number of electrical devices are being used in a small area.
The electrical and radio waves can disrupt each other’s signals. This can cause errors in
binary data, or causes devices to disconnect from the network.
Security breaches
Security breaches can be caused by malware or by hackers. For example, if a firewall
hardware device were hacked, its rules could be changed to allow any data into the
network, which could result in the system being overloaded and could cause errors in
the binary data being transmitted.
Hardware failure
If a network switch were to fail, this could cause errors in data transmission, with
packets no longer routed to the correct places.

71
369825_9.2_Cam_LSC_SB_055-087.indd Page 72 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Parity-checking
KEYWORDS
How can we check that data is received
parity-checking: type of error check
accurately by another device? Parity-checking! that ensures data has been transmitted
Parity checks are used to make sure that data correctly
has been sent and received correctly. Devices byte: eight bits of data, e.g. 01010011
transmitting data between each other agree to parity bit: bit added to a byte to make
use either an odd or even protocol for parity- the total number of 1 bits either even or
checking. odd

If devices have agreed that they will use an even number of bits, then any data
received should have an even number of 1s within it, so a byte would have two 1s,
four 1s, six 1s or eight 1s in total. The parity bit is set to either 1 or 0 to ensure that the
total number of 1s is even. For example, if the first 7 bits are 1001100, then the parity
bit would be set to 1 to make four 1s in total; if the first 7 bits are 1001000, then the
parity bit would be set to 0 as there is already an even number of 1s in this byte.

If any bytes are received that have an odd number of 1s, then this data has an error
and would need to be sent again.

Where devices have agreed that an odd number of bits should be sent (for example
one 1, three 1s, five 1s or seven 1s), if there are an even number of 1s, then the data
contains an error and would need to be sent again.

Example 1
Computer 1 and Computer 2 have agreed to use an even checking system.

Computer 1 sends the byte:

0 1 0 1 0 1 0 1

Computer 2 receives the byte:

0 1 0 1 0 1 0 1

The byte received by Computer 2 has four 1s, which is an even number.
There is no error.

Computer 2 receives the byte:

1 1 1 1 1 1 0 1

There has been an electrical surge and the byte received by Computer 2
has seven 1s, which is an odd number. There is an error.

72
369825_9.2_Cam_LSC_SB_055-087.indd Page 73 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Example 2
A mobile phone and a tablet device have agreed to use an odd checking system.

The tablet device receives the byte:

0 1 1 1 0 1 0 1

The byte received by Computer 2 has five 1s, which is an odd number.
There is no error.

Parity checks give computers a way to check for errors. They can detect errors quickly
and require little computing power. However, this check does not identify which bit is
incorrect, if an error is detected, so the data has to be re-sent.

Practise
1 Answer the following questions in pairs.
a What is a parity bit?
b How can a parity bit help in error detection?
2 Look at each example below. Say whether an error would be detected and explain the
reason for each answer.
a A smart watch and a mobile phone have agreed to use an even parity-checking
system. The mobile phone receives the following byte:

0 1 1 1 1 1 0 1

b A PC and a server have agreed to use an odd parity-checking system. The server
receives the following byte:

0 1 0 0 0 1 0 0

c A tablet and a PC have agreed to use an odd parity-checking system. The PC


receives the following byte:

0 0 0 0 0 0 0 0

73
369825_9.2_Cam_LSC_SB_055-087.indd Page 74 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Keeping it all secure


Learn
In companies, schools or governments, the data contained in packets that speed around
networks can be extremely valuable to the organisation that owns them. Often, the
organisations rely on the data they have about their customers, students or products to
be able to continue successfully. Some of the data is personal data, which means that
companies have a legal responsibility to look after it carefully.
A dataset is a collection of data that is stored in a table, or multiple tables. An example of
a simple dataset is shown below, and includes how much money an employee is paid per
year, along with their personal details.

Full Name Address Country Pay per year KEYWORDS


Luis Garcia PO Box 325, 2864 Enim St Spain $57,711.00 dataset: collection of
Athena Levy Ap #426-1625 Erat. Rd United Kingdom $41,751.00 related information
that a computer can
Dominic Compton 9665 Vitae Road Canada $35,326.00 manipulate
Lenore Berg PO Box 288, 4870 Natoque Ave India $65,103.00 table: set of facts or
Neve Hart 565-7129 Lectus Street Austria $59,849.00 figures that are set
out in a column and
Vera Townsend 271-2412 Et St France $51,792.00 row structure
Ju Yang 657-1640 Felis. Ave China $14,589.00
Aamandu Abebe Ap #414-3963 Arcu. Rd South Africa $16,563.00
Porter Dickson Ap #886-4114 Sed Ave United States $30,379.00
Nelle Sosa Ap #537-5164 Pede Street United States $17,371.00

It is crucial that this information is kept safely and cannot be accessed by anyone who
is not authorised to do so, as people could be identified from the information, and the
information is private. Other examples of private information include:
l medical records
l school records
l police records
l customers’ information kept by businesses
l bank details.

For example, would you be happy for


your school records to be made publicly
available for other people to see?
What effect could this have on your
opportunities in the future?
Network managers need to make sure that
the datasets on their networks are kept
safe, which is a challenging task when
there are lots of threats to data.
Here are some ways in which organisations
can keep datasets safe on networks.

74
369825_9.2_Cam_LSC_SB_055-087.indd Page 75 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Firewalls
Most networks, especially business networks, use a firewall. This is a special type of
­network hardware (or software) that examines the incoming and outgoing network
­traffic to check for security risks and blocks any suspicious activity.

Firewalls can protect datasets by blocking access to the data from outside the network,
or from specific parts of the network.
User access controls
User access controls enable network managers to allow some users access to the data-
sets, but not others. This could be useful in a school, for example, by allowing teachers
to view the datasets about student progress and parental contact details. It would not
be a good idea to allow students access to this information, in case it was misused.

Often, some accounts will be grouped as KEYWORDS


administrator accounts, which is the type of
administrator: account with top-level
account the network manager would have.
access, with the ability to change settings
In a school, it is likely that there would also or add and remove users from a network
be ‘staff’ and ‘student’ account groups, that character: single letter, digit or symbol
could access different parts of the network.
hacker: somebody who tries to gain
Password policies unauthorised access to a computer
system or network
To prevent unauthorised access to a network, brute-force attack: type of unauthorised
it is important that network managers create access to a computer system that uses a
strong password policies for their users. This large dictionary to try multiple password
helps to make sure that users create stronger combinations until it is successful
passwords. biometric security: security method
that identifies people using a physical
Here are some of the rules that may be attribute (e.g. a fingerprint) or a
included in the policy. behaviour (e.g. a hand gesture)
l Passwords must two-factor authentication: method of
signing into a system that requires two
– contain letters, numbers and symbols
types of authentication (e.g. a password
– be longer than ten characters and a one-time SMS message code)
– not contain the user’s name
– not contain a date.
l Users must change their passwords regularly.

Using long and unpredictable passwords helps


to keep datasets secure, as it would take much
longer for hackers to gain access using a brute-
force attack.
Biometric security and two-factor
­authentication
Other methods that network managers could
use to keep the network safe are biometric
security and two-factor authentication.

75
369825_9.2_Cam_LSC_SB_055-087.indd Page 76 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Biometric security requires a user to sign into systems using a biological password,
such as a fingerprint, facial recognition or an iris scan. This method of authentication
is becoming increasingly popular, with more and more devices supporting it.

Two-factor authentication can be used to authenticate a user. This is where a user


is asked to confirm their identity using a second device. Often a code is sent to the
second device, such as a mobile phone, which must be entered via the main computer
to complete the log-in process. This adds an additional layer of security, making it
harder for someone to gain unauthorised access to the system.

Biometric security and two-factor authentication are powerful policies that a network
manager can put in place for certain staff, for example teachers, so that important
information can be protected.
Encryption
If data is sent between devices as plaintext, then a hacker could intercept the data. If
a teacher wanted to access details of a student from their laptop at home, if the data
were not encrypted and was sent as plaintext, a hacker could intercept the data and
read the contents of the data packets. Network managers can make sure that all data is
encrypted using secure protocols, such as HTTPS.

Levels of security – a compromise!


While it would be best if all the methods above
KEYWORDS
were used to keep a network secure, in reality
this is not always possible. There is a fine balance fingerprint recognition: system that
between devices being usable and devices being matches a real-time image of a human
fingerprint with a database of saved
ultra-secure. fingerprint representations to allow a user
For example, if a school has a ‘no mobile phones’ access to a digital device
policy for students, then it would not be possible facial recognition: system that matches
to ask students to use two-factor authentication a real-time image of a human face with a
database of saved facial representations
every time they want to log in. Biometric to allow a user access to a digital device
scanners for all students and staff devices would
authenticate: confirm a user’s details
be extremely expensive. Some systems within to ensure that they should be allowed
school do not hold personal data, so it is not as access to a system
important for them to be secure. Imagine if you plaintext: text that has not been
were asked to change your password every day; it encrypted and can be read if it is
would make the system very secure, but it would intercepted
be extremely hard to remember your password! protocol: agreed set of rules that
computers follow to communicate with
Network managers always need to consider the each other over a network
cost of a security method, how easily users need artificial intelligence (AI): ability of a
to be able to access systems and how securely computer system to learn and develop its
the data needs to be stored. own programming from the experiences
it encounters
Machine learning in network security
machine learning: ability of a computer
Innovative approaches to keeping networks system to learn over time
safe have been rapidly transformed by artificial
intelligence and machine learning. Newer cloud

76
369825_9.2_Cam_LSC_SB_055-087.indd Page 77 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

products now use machine learning to find threats. For example, if an IP address is linked
to a known hacker or security risk, firewalls with machine learning enabled will use this
information to look for this IP address and block it from accessing the network.
Machine learning can also detect when a login looks suspicious and block it, for example,
if a user tries to log in from a location that they do not usually use.

Practise
1 When designing network security, costs need to be considered. Create a table with
two columns: ‘Hardware’ and ‘Costs’. Find the cost of each of the following pieces of
network hardware, which will help you in the tasks that follow.
a Network switch
b Router
c Wireless access point
For this task, imagine that you are
d Ethernet cable a network manager, responsible for
e Firewall (hardware) keeping data safe on your network.
2 Discuss each of these scenarios with However, you also need to make
your partner. sure that data is as accessible as
l How secure does the data in the
possible for the people who need it.
Remember: hardware devices are
scenario need to be? Would it
quite expensive and can have a big
be damaging if this data were
impact on your budget, so you should
exposed? buy network hardware only if you
l How many ‘groups’ of users are really need to.
present in the system? (For example,
Customers and Staff)
l What security measures would you want to put in place?
l What would be the total cost to put these security measures in place, based on the
hardware costs you found in the previous task?
a Scenario 1
You are the network administrator for a large car sales garage. Sales assistants
can work remotely to access customer records, so that they can make sales calls
from home. All staff in the organisation are provided with a laptop when they start
­working for the company. Managers in the company are given an upgraded laptop
and also have access to the personal details of the sales assistants, so that they can
contact them when required.
b Scenario 2
You are the network administrator for a restaurant business. There are three
Wi-Fi-connected laptops in the restaurant that the table staff use to input food
orders. A dataset is used to keep track of how well each food item sells. The laptops
have built-in fingerprint readers, but they are not currently being used. Staff have
not changed their passwords in over five years and the network does not have a
­firewall in place.

77
369825_9.2_Cam_LSC_SB_055-087.indd Page 78 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

c Scenario 3
A large bank in a city centre has hundreds of bank staff, IT specialists and managers.
The bank has three confidential datasets that it needs to protect: one containing the
personal details of all the staff; one containing private banking information; and one
containing customer details. The bank requires the highest level of security to keep
their data safe.
3 Explain to your partner how using a machine-learning security feature could improve
the security of a network.
a What would happen if somebody tried to log into the system from another country?
b What would happen if somebody tried to log into the system from another device?
c If a particular IP address has been identified by cloud software as a threat, what
action could it take if this device tried to access the system?

Go further
Error-checking during data transmission is all about trying to work out whether a
problem has occurred when transmitting data between devices. One problem with using
a parity check is that this type of check does not identify where the error has occurred.
You just know that there is an error, which means that the data has to be transmitted
again.
This is where two-dimensional parity checks
KEYWORDS
are used instead. Two-dimensional parity checks
two-dimensional parity check: check
allow you to identify exactly where the error
for finding where an error exists within a
exists in the data that has been transmitted. parity check
To do this, devices need to send a parity byte parity byte: byte added to a block of
in addition to the bytes of data that are to be data to check whether the data is valid or
transmitted. This means that data is sent in invalid
blocks, rather than one byte at a time. block: string of data (0s and 1s)
The parity bits and parity byte are used to parity bit: bit added to a byte to make
the total number of 1 bits either even or
determine whether the data has been transmitted odd
correctly using this process.
1 First, the parity bit for the byte of data in each
horizontal row is identified. In this example, even parity is being used.

Parity Bit 1 Bit 2 Bit3 Bit 4 Bit 5 Bit 6 Bit 7


bit
Byte 1 0 0 1 1 1 0 0 1 EVEN
Byte 2 0 1 0 0 0 0 0 1 EVEN
Parity byte

Step 1: Calculate the parity bit for each byte of data.

78
369825_9.2_Cam_LSC_SB_055-087.indd Page 79 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

2 Then, the parity byte is worked out by looking at the bits in each vertical column and
making sure that the parity bit identified is following the same odd or even rule. In this
example, using even parity, the total number of 1s and 0s in each column should be
even.

Parity Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7


bit
Byte 1 0 0 1 1 1 0 0 1 EVEN
Byte 2 0 1 0 0 0 0 0 1 EVEN
Parity byte 0 1 1 1 1 0 0 0 EVEN
EVEN EVEN EVEN EVEN EVEN EVEN EVEN EVEN

Step 2: Calculate the parity bit for each column of data.


l The parity byte is transmitted along with the rest of the data, and each byte of main
data includes a parity bit.
l The receiving device will check that each row and column of the block of data sticks to
the even parity rule. If they do, then the data has been transmitted successfully.
If an error has occurred during data transmission, then using parity-checking in this way
will also identify where the error has occurred.
The example below, which is a larger block of data, uses an even checking system, so all
rows and columns should be even. However, you can see that the checks for byte 2 and
bit 6 have failed, identifying where the error has occurred. The bit where the row and
column intersect can now be flipped to fix the error.

Parity Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Odd/Even


bit
Byte 1 0 1 0 1 1 0 0 1 EVEN
Byte 2 0 1 0 1 0 1 1 1 ODD
Byte 3 0 0 1 0 1 1 0 1 EVEN
Byte 4 0 1 1 0 1 0 1 0 EVEN
Parity byte 0 1 0 0 1 0 1 1 EVEN
Odd/Even EVEN EVEN EVEN EVEN EVEN EVEN ODD EVEN

1 To remind yourself of how to perform a parity check,


identify which of the following bytes have been
transferred correctly, if even parity has been used.
Look back to the
a 11010000
‘Checking for errors’
b 01100110 section for a reminder
c 11110101 about parity-checking.
d 10111001
e 00111111

79
369825_9.2_Cam_LSC_SB_055-087.indd Page 80 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

2 Open the file Calculating Parity Bits.docx provided by your teacher. Calculate the
parity bit for each question.
3 The example below (that has been received by a device) uses odd parity.
a Copy and complete the table below, identifying whether each column and row is
odd or even.

Parity Odd/
bit Even
Byte 1 0 1 1 0 0 0 1

Parity byte 0 1 0 0 0 1 1 0

Odd/Even ODD

b Identify which bit is incorrect.


4 Open the file Calculating Parity Blocks.docx provided by your teacher. Complete
the questions to calculate the parity bits and parity byte to discover the errors in the
transmission data.
5 In pairs, explain to each other what a parity bit is and why it is useful when checking
for errors.

Challenge yourself
Network administrators often use the KEYWORDS
command line to manage their network, or command line: a way of using an operating
devices on their network. system that is navigated by typing
commands
A command line is another way to access
operating system: software that manages
the operating system, without the need for a all the computer hardware and software; it
graphical user interface (GUI). For expert users, also acts as an interface between computer
common tasks can be completed more quickly hardware components and the user, and
using the command line, and it allows for more provides a platform where applications can
advanced operations, such as sharing folders run
across the network, analysing packets of data graphical user interface (GUI): way of using
sent around the network, and much more. software that is navigated by pointing and
clicking on graphics on a screen
Network administrators need to learn how to
use the command line when they are training
for their role.

Accessing the command line (MS-DOS)


The command line allows you to type
in commands to perform actions on the
computer, instead of using a GUI to perform
the actions. There are a number of ways
to access the MS-DOS command line in
Windows. The easiest way is to go to the
Start Menu and type in run, then press
Enter on your keyboard.

80
369825_9.2_Cam_LSC_SB_055-087.indd Page 81 09/03/23 8:39 AM A4902 /Data%20Disk/Manoj%20R/2023/March/09-03-23/HO02737_142

Unit 9.2 Design your own network: Shape and size

When the Run window appears, type in cmd, then press Enter. You are now in the MS-
DOS command line.

This shows you which folder you are currently in. In the example above, ‘Network Admin’
is the username of the computer.
1 Use the command md to create a folder called ‘network-users’. Use the example below
to help you.

81
369825_9.2_Cam_LSC_SB_055-087.indd Page 82 09/03/23 1:08 PM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

2 Use the command dir to list all the folders in the current folder that you are in. If you
created your ‘network-users’ folder correctly, you should see it in the list.

3 Change into the ‘network-users’ folder that you have created. At the moment, there
will be no files or folders in there.
Use the command cd (change directory) to move into the ‘network-users’ folder. Use
the following example to help you to complete the command.

82
369825_9.2_Cam_LSC_SB_055-087.indd Page 83 09/03/23 1:09 PM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

4 You now need to create folders for five users on the network. Pick the names of five
people in your class and use the example below to help you to write a command to
create folders for all the users.
You will use the md command, but this time you will be creating multiple folders.

5 To check that this has worked properly, use dir to list the files in your ‘network-users’
folder.

83
369825_9.2_Cam_LSC_SB_055-087.indd Page 84 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

6 Examine the folders that you have created using Windows Explorer. Windows Explorer
is the application that allows you to view your files when using the GUI version of
Windows. You can access it via the Start Menu, by clicking the Start Menu and then
clicking on Documents and navigating through your files.
Click on This Computer, then your Hard Drive (usually C: drive), then Users, then
your username. In here, you should find your ‘network-users’ folder.
Have a look inside the ‘network-users’ folder to see whether your folders are there.

7 There are many commands that network


administrators find useful to help them to
It is important that you use
manage their devices. There are too many to
commands only if you are sure
remember them all, but Windows has a ‘help’
that you know what they will do:
menu built in, which lists other commands for example, it could be easy to
that can be used. run a command that deleted all
Go to a command line and type in help to your files from the computer!
investigate some of the other commands that
can be run.

84
369825_9.2_Cam_LSC_SB_055-087.indd Page 85 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Final project
Look back to the start of this unit to remind yourself of the Scenario. Your task is to
create a presentation to advise the youth centre on best practices for establishing a
safe, monitored and flexible online environment.
The network must support:
l five PCs
l ten laptops
l five tablets
l fifteen smartphones
l two games consoles
l five smart watches.

Use Microsoft Word to plan the content of your presentation, and then use Microsoft
PowerPoint to create your final presentation which should meet the criteria from the
youth centre.
Part 1: Network topology
Make recommendations to the youth centre on the type of network topology you would
recommend and the hardware you think they would need to support the setup of their
local hub.
On paper, draw a network topology diagram that shows the layout of the network, with
the hardware that you have chosen to include. It is important that you identify what
type of topology your diagram shows (bus, ring or star).
Write notes on your Word document to include the following:
l A network hardware shopping list, with a short justification of why each item is
needed.
l A list of the software tools that a network administrator might need to manage the
network.
– What are they called?
– What would they be used for?
l Identify two protocols that your network will use.
– What are they called?
– Why would they be used?
l If the hub were to expand at a later date to double the number of devices it could
support, what additional network hardware would you put in place and why?
– How would this improve the scalability of your network?
– If the youth centre were to grow the number of users, what could happen if you
had not planned for it?
l Explain how parity-checking could improve the validity of data on your network.
– How does parity-checking work? What does it help to find?
– What is a parity bit?

85
369825_9.2_Cam_LSC_SB_055-087.indd Page 86 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

l Discuss how the security needs at each level of the network may vary. The youth
centre will employ management staff, network staff and teaching staff and will also
have user accounts for students. There are some highly personal datasets that need
to be accessed by some accounts.
– Which accounts would you give the higher-level access to and why?
– What would each staff member have access to?
– What other methods could you use to secure information on the network?
Part 2: Presentation
Use your planning document to create your presentation.
Create a presentation that outlines the following:
l Slides 1–2:
– A screenshot or picture of your network topology diagram.
– A justification of why you have chosen to set the network out in the way that you
have.
– A list of the hardware that will be needed to set up the network.
l Slide 3:
A list of software tools that a network administrator may need to help them to
operate and maintain the network, and an explanation of what each one would be
used for.
l Slide 4:
Details about which network-security protocols will be used to keep data packets
secure.
l Slide 5:
An explanation about how using parity bits and parity blocks can check for errors, to
reassure the hub staff that the network setup will be robust; assume that they do not
know anything about how data is transmitted, so you will need to explain the process
to them.
l Slide 6:
Explain how you intend to:
– secure the information on the network
– control users’ access the network, and explain why you have chosen these
methods
– keep the datasets secure.

86
369825_9.2_Cam_LSC_SB_055-087.indd Page 87 06/03/23 11:10 AM A4902 /142/HO02737/work/indd

Unit 9.2 Design your own network: Shape and size

Evaluation
1 Swap presentations with your partner or listen to each other’s presentation. Make
notes that comment on the following:
a Does it cover all the requirements?
b Is the content easy to understand?
c How could the network topology be improved?
d Make a list of recommendations of how they could improve their report/network
topology diagram.
e Feed back your recommendations to your partner.
2 When you receive feedback from your partner, read the recommendations carefully.
Use the feedback that you have been given to improve your presentation.

What can you do?

Read and review what you can do.


4 I can explain how different network topologies (bus, ring and star) transfer
information between devices.
4 I can explain the role of protocols in data transmission.
4 I can explain what scalability factors are and how scalability can affect a network.
4 I can explain why scalability should be considered when designing networks and
how networks can be designed to scale up.
4 I can explain what a parity bit is and its role in error detection.
4 I can perform parity-bit and parity-block calculations and identify errors in data
transmission.
4 I can explain the choices that must be made when securing information on a
network, including cost, accessibility and the relative security requirements of
different datasets.

87
369825_9.3_Cam_LSC_SB_088-128.indd Page 88 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit Coding and testing: Game


9.3 development for the micro:bit

Get started!
Have you ever wondered how a computer game is developed to
use a physical device as a key component in gameplay? For
example, the Nintendo Switch allows both sides to be
removed and used as individual controllers within the game
displayed on the screen.
Discuss with your partner:
l What computer games do you play that include a physical device?
l How is the physical device used in the game?
KEYWORDS
The micro:bit is a physical device: a small microprocessor that
physical computing
has a range of inputs and outputs. The data that is gathered device: device that can
by the micro:bit can be used in many ways: for example, be programmed using
pressing the A button sends data to the microprocessor and, block or text-based
if programmed, the micro:bit will react to this input. programming languages
microprocessor: device
In this unit, you will learn to develop a program using that has one circuit but the
MicroPython for the micro:bit to create a simple game. The input, process and output
game will use more than one of the inputs to allow the user to functions of a computer
interact with the game. The display and the buzzer will allow data: raw facts and figures
the user to see and hear the output from the game.

Learning outcomes
In this unit, you will learn to: l identify and explain the purpose of a
l follow, understand, edit and correct one-dimensional array
algorithms that are presented as l identify and describe data types in
pseudocode MicroPython programs including integer,
l follow flowchart or pseudocode real, character, string and Boolean
algorithms that use loops l develop MicroPython programs with
l create algorithms using flowcharts and count-controlled loops
pseudocode l access data from an array using
l explain and use iteration statements MicroPython
with count-controlled loops in either l use iterative development on micro:bit
pseudocode or flowcharts prototypes to create solutions to
l predict the outcome of algorithms that problems
use iteration l develop and apply test plans that
l compare and contrast two algorithms include normal, extreme and invalid data
for the same solution and decide which l identify test data that covers normal,
is best suited to the task extreme and invalid data
l create an algorithm as a flowchart l use a trace table to check the flow of a
or pseudocode using more than one variable or array through an algorithm
construct: sequence, selection and l program a micro:bit to use data to solve
count-controlled iteration a problem.

88
369825_9.3_Cam_LSC_SB_088-128.indd Page 89 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Warm up
1 In pairs, consider a basic game that you
have played on a computing device. There
are many inputs and outputs that are used
to allow you to interact with a game. For
example: in the game Tetris, the aim is to
guide the different-shaped blocks to the
bottom of the screen and position them to
complete a horizontal line.
2 Discuss the game Tetris, shown here, with
your partner.
a How do you control the blocks?
b How do you know when a game starts?
c How do you know when a horizontal
line is matched up? If you’ve never played Tetris,
discuss possible answers with your
d How do you know when you win?
partner, and then compare answers
e How do you know if you lose? with a pair who have played the
You can see how Tetris is played here: game.
https://tetris.com/play-tetris

DID YOU KNOW?


Computer games have developed at a
fast rate, from the first simple games of
Snake or Pong in the early 1970s, to
the graphic-rich game environments
accessible today. Pong was the first ever
computer game; it allowed two players to
control lines on each side of the screen to
keep a ball moving between them.
Games today have graphics that are
much more sophisticated than the
Pong example, and allow the player to
immerse themselves in a game with a
story: for example, saving a character or
attack scenarios.
Games on devices such as Nintendo
Switch, Xbox or PlayStation have
become one of the favourite
pastimes of people today. In
the past, games were played on
desktop computers. Today, having
a game that includes physical
devices, for example individual
handheld controllers, such as
those for the Nintendo Switch,
or that is played on a computing
device such as the PlayStation,
further increases its popularity.

89
369825_9.3_Cam_LSC_SB_088-128.indd Page 90 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

SCENARIO
You are likely to have played a computer-
based game that allows you to interact with
A ‘What am I?’ game
it, whether that is through the use of the allows one player to ask questions to try
keyboard or an external physical device such to discover the name of an object/animal/word.
as a joystick. Either way, the physical device The other player can answer only ‘yes’ or ‘no’
allowed you to play and experience the game. until the first player guesses correctly. The object/
animal/word can be shown on a device placed on
Games have a wide range of purposes, and the first player’s head so that they cannot see it.
they can be used in an educational way, to Once they have guessed correctly, the player
help students to learn through games. Your either moves the device or presses a button
school has asked you to create a prototype to access a new object/animal/
game on the micro:bit that acts as the word to guess.
physical device of a ‘What am I?’ game.

The game should:


l display a random item from a pre-set list to the player
l use an input either through the accelerometer or a button to represent when the
player has correctly guessed, and play a tune to represent a correct answer
l reset through another input, to start the game again
l create a new image to be stored in a variable
l use speech, music and images within the game
l utilise a count-controlled loop, selection, array and variables
l use a time delay to aid gameplay.

Do you remember?
Before starting this unit, you should be ✔ identify and use conditional operators in
able to: a conditional statement
✔ create a program for the micro:bit using ✔ send a program to the micro:bit
selection in MicroPython ✔ create a flowchart using sequence and
✔ identify and use a range of inputs and selection
outputs available on the micro:bit ✔ follow and understand an algorithm
✔ identify and use conditional operators presented as a flowchart or pseudocode
to combine more than one input in a ✔ develop a test plan with a range of data
conditional statement inputs.

Before starting this unit, you will need to You will also need the following physical
access MicroPython on a computer through computing devices:
online software. To access MicroPython: l Micro:bit
1 Open your chosen web-browser l USB cable
software. l Optional battery pack for the micro:bit.
2 Go to https://python.microbit.org

90
369825_9.3_Cam_LSC_SB_088-128.indd Page 91 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Micro:bit recap
Learn
The micro:bit is a physical computing device
that can be programmed directly. You should
already have used it in activities in previous
stages. The text-based programming
language that is used with the micro:bit is
MicroPython, which is a version of the
Python programming language.
The micro:bit is a microprocessor. It is a small
device that fits in your hand and can store
and run one program at a time. The program
is downloaded from specific websites. The
program can be developed as a block-
based program on the platform MakeCode.
The platform that uses the text-based
programming language MicroPython is
KEYWORDS
https://python.microbit.org
text-based programming: written lines
The micro:bit itself has a set of inputs and outputs of code using a specific programming
that can be used in a program. language, e.g. Python
l The inputs are: MicroPython: programming language
used on the micro:bit
– A button
microprocessor: device that has one
– B button
circuit but the input, process and
– accelerometer (detects movement and output functions of a computer
direction) program: instructions that tell a
– microphone (a sound sensor) computer system how to complete
– light sensor (located on the display) a task

– temperature sensor (located in the block-based program: individual code


blocks connected together to create a
processor). program
l The outputs are: platform: hardware and operating
– display (25 individual LED lights) system that runs an application
– buzzer (located on the reverse of the accelerometer: detects a change in
micro:bit). direction of a device
general-purpose input output (GPIO):
There are also general-purpose input/output pins at the bottom of the micro:bit that
(GPIO) pins at the bottom of the micro:bit allow additional inputs and outputs to
that allow the micro:bit to connect to external be added through crocodile clips
components via crocodile clips. crocodile clips: cable for creating
a temporary electrical connection
Like any programming language, the syntax of between devices
MicroPython is specific and needs to be written syntax: specific rules used in a
correctly for the program to run. If a program is not programming language
written correctly, then a syntax error will be found. syntax error: error in program code
This is shown on the micro:bit as a sad face followed that stops the program from running
by the line on which the error has been found.

91
369825_9.3_Cam_LSC_SB_088-128.indd Page 92 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Look at the pseudocode below for a micro:bit


program that uses the accelerometer to detect
movement. When the program starts, the micro:bit
outputs four different arrows in turn, pointing north
(up arrow), east (right arrow), south (down arrow)
and west (left arrow).
l If the micro:bit is tilted to the left, then the arrow
will point to the left and display for 2 seconds.
l If the micro:bit is tilted to the right, then the
arrow will point to the right and display for
2 seconds.
l If the micro:bit is tilted up (forwards towards
you), then the arrow will point down and display
for 2 seconds. KEYWORD
l If the micro:bit is tilted down (backwards away pseudocode: textual representation of
from you), then the arrow will point up and an algorithm
display for 2 seconds.
START
OUTPUT arrow N
DELAY 300
OUTPUT arrow E
DELAY 300
OUTPUT arrow S
DELAY 300
OUTPUT arrow W
DELAY 300

IF micro:bit moved to left THEN


OUTPUT arrow W
DELAY 2000
ENDIF
IF micro:bit moved to right THEN
OUTPUT arrow E
DELAY 2000
ENDIF
IF micro:bit moved forwards THEN
OUTPUT arrow S
DELAY 2000
ENDIF
IF micro:bit moved backwards THEN
OUTPUT arrow N
DELAY 2000
ENDIF
STOP

92
369825_9.3_Cam_LSC_SB_088-128.indd Page 93 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

This program requires the use of the accelerometer built into the micro:bit. The
accelerometer can detect the change in direction of the device.
The accelerometer is continuously gathering data from the movement that the micro:bit
makes. This data is then used to activate an output.
In MicroPython, the code for using the accelerometer is:

The specific test for the direction is placed in the brackets and encased in single quotation
marks.
The different options include:
l up l left l face up l freefall
l down l right l face down l shake.
The MicroPython can be developed from the pseudocode plan by following these steps.
1 Set the program to use MicroPython. All programs
must start with this code. The use of while True
allows the program to check continuously whether an
input is being used.
2 Add the program code to show a changing arrow
that looks like it is rotating.
OUTPUT arrow N
DELAY 300
OUTPUT arrow E
DELAY 300
OUTPUT arrow S
DELAY 300
OUTPUT arrow W
DELAY 300

Remember that it is important to indent (move in)


the code under the while True line.
sleep(300) is used to add a short delay between the images being displayed. A delay is required
to allow each image to be seen.
Notice the code for displaying an image: display.show(Image.ARROW _ N).
This is used for any image, with the image to be displayed in
uppercase letters at the end.

93
369825_9.3_Cam_LSC_SB_088-128.indd Page 94 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

3 Add the conditional statement to check whether the micro:bit is tilted to the left.
IF micro:bit moved to left THEN
OUTPUT arrow W
DELAY 2000
ENDIF

Notice that: KEYWORD


the conditional statement (if) is in line with the previous line of conditional statement:
code, and the code to be run if this is True is indented below the if completes a check to
see whether set criteria
sleep(2000) is used to display the image for the specific direction is either True or False
for 2 seconds before the program returns to displaying
the rotating arrows.

4 Develop the program to add the other three conditional statements to check whether
the micro:bit is being tilted in any of the other directions.
IF micro:bit moved to right THEN
OUTPUT arrow E
DELAY 2000
ENDIF
IF micro:bit moved forwards THEN
OUTPUT arrow S
DELAY 2000
ENDIF
IF micro:bit moved backwards THEN
OUTPUT arrow N
DELAY 2000
ENDIF

94
369825_9.3_Cam_LSC_SB_088-128.indd Page 95 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

5 Download the program onto the micro:bit, ready for testing.


a Connect the micro:bit to the computer through the USB cable.
b Connect the micro:bit by clicking the send to micro:bit icon on the platform.
c Select the micro:bit from the pop-up.
d Send the program to the micro:bit.
6 Create a test plan to test a range of data:
– Normal test data is an expected input that the program should run as normal, for
example a specific movement set in the program, such as tilt left.
– Extreme test data is something at the upper or lower boundary of what should be
accepted. This is not relevant when checking the tilt of the micro:bit as the angle
cannot be controlled precisely.
– Invalid test data is an input that will not do anything in the program. Here, another
input is checked to make sure that it does not disrupt the program: for example,
pressing one of the buttons as an input from these is not part of the program code.
Test Input data Expected outcome Pass/fail
1 Normal No movement Continuous change in image from arrows pointing up, right, Pass
down and left with a very short delay between images.
2 Normal Tilt left Arrow to the left is displayed for 2 seconds and then returns to Pass
moving arrow.
3 Normal Tilt right Arrow to the right is displayed for 2 seconds and then returns to Pass
moving arrow.
4 Normal Tilt forwards Arrow down is displayed for 2 seconds and then returns to Pass
moving arrow.
5 Normal Tilt backwards Arrow up is displayed for 2 seconds and then returns to moving Pass
arrow.
6 Invalid Press the A button No change Pass
7 Invalid Press the B button No change Pass

The test plan above shows that the program and the use of the accelerometer works as
expected.

KEYWORDS
test plan: document that details the tests to extreme test data: acceptable input but at the
be carried out when a program is complete and ends of the possible input range
whether or not they are successful invalid test data: data that should be rejected by
normal test data: data of the correct type that a program
should be accepted by a program

95
369825_9.3_Cam_LSC_SB_088-128.indd Page 96 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
DID YOU KNOW?
1 Discuss with your partner what the pseudocode below is Another device that
designed to do. has an accelerometer
START in it is a smartphone.
As you move the mobile
IMPORT random library phone from portrait to
number = 0 landscape, the display
moves with it.
OUTPUT happy face
DELAY 300
OUTPUT sad face

IF micro:bit shaken THEN


number = random number between 1 and 2
IF number == 1 THEN
OUTPUT happy face
DELAY 2000
ELSE
OUTPUT sad face
DELAY 2000
ENDIF

STOP

2 Create a test plan using the template below, using normal and
invalid test data, so that it is ready to use when the program
has been created.

Test Input data Expected outcome Pass/fail

3 Open the file RandomQuestionOutput.py provided by your


teacher.
a Develop the MicroPython program to match the
pseudocode above. To add a random number, you will need KEYWORDS
to use the following code: random value:
number = random.randint(1, 2) randomly generated
This will assign a random value between 1 and 2 to the number in a program
variable ‘number’. that can be set within
a range
b Connect the micro:bit and send the program to it.
variable: named
4 Complete the test plan you set up in task 2 to check that the memory location that
program works correctly with the normal and invalid test data. can store a value

96
369825_9.3_Cam_LSC_SB_088-128.indd Page 97 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

5 a Discuss with your partner how the program is using the


accelerometer. Change the accelerometer movement that
is being detected in this program and test the impact on
the program by trying the original movement and the new
movement.
b

Remember that the different accelerometer


movements to be used as an input are up, down,
left, right, face up, face down, freefall and shake.

Download the program to your computer and save it.


– Select the three vertical dots next to the Save icon.
– Select Save Python Script.
– Move it from the ‘Downloads’ folder to your own folder
and save it as randomQuestionOutput.py.

Arrays and micro:bits


Learn
In Unit 9.1, you explored how more than one item KEYWORDS
can be stored in an array. A variable can store only array: data structure in a program
one item. An array can hold multiple items. The that can store more than one item
of data of the same data type under
micro:bit can work with an array. a single identifier; data items can be
To set up an array in MicroPython, at the start changed
of the program you need to use the syntax naming convention: the way
arrayName = [ ]. The naming convention for an a variable or array is named in
programming
array is the same as you would use for a variable:
camelCase: all lowercase, and from
l camelCase – no spaces, and from the second
the second word the first letter is
word the first letter is capitalised capitalised
l snake_case – no spaces; spaces are replaced with snake_case: all lowercase, and spaces
underscores. are replaced with underscores ( _ )
integer: whole number
The program below shows an array that has been
set up to store five integer values. An integer is a data item: piece of information that
represents part of the data that
whole number. makes up a person, place or thing,
e.g. some of the data items that
represent a person are their first
name and second name
If the data items were strings, they would each be
string: sequence of characters that
placed inside quotation marks: can be text, numbers or symbols;
quotation marks around the
characters define it as a string

97
369825_9.3_Cam_LSC_SB_088-128.indd Page 98 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Every item in the array is assigned a position, or index. The


KEYWORD
first position is always ‘0’ and they increase by 1.
index: numerical reference
Position 0 1 2 3 4 for a location of a piece of
data stored in an array
Array item 50 25 65 90 33

These index positions can help to identify the specific item to be used or output to the
micro:bit display. To output the item that is stored in position 2, you need to use the
syntax to display something on the screen: display.scroll(). The array details are placed
inside the brackets. The format for this is the name of the array followed by the position
you want to output in square brackets:

This would output the value 65 for the array above.


Sometimes, you may want to add a new item to the array while the program is running.
This is done using append(), which adds the item to the end of the list. In the example
below, the number 12 will be added at index position 5:

The table below shows the array used in the program code above and the different
positions the items are in.
Position 0 1 2 3 4 5
Array item 50 25 65 90 33 12

You can check that 12 has been added correctly by outputting the contents stored at
position 5 of the array. You can do this by:
l using the MicroPython code to output to the display: display.scroll()
l adding the name of the array inside the brackets: display.scroll(score)
l adding the position of the item you want to output in square brackets after the array
name: display.scroll(score[5]).

98
369825_9.3_Cam_LSC_SB_088-128.indd Page 99 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

The position in the array can be used in a program to output a random value. You have
generated a random number in the previous section. In the pseudocode below, the
micro:bit will generate a random selection from a list of six numbers.
START KEYWORD
IMPORT random library random value: randomly
generated number in a program
ARRAY numbers = [1, 2, 3, 4, 5, 6] that can be set within a range

IF micro:bit is shaken THEN


OUTPUT a random item from numbers
DELAY 500
OUTPUT clear screen
ENDIF
STOP

The program can be completed by following these steps.


1 After the main micro:bit library has been imported, the random library must also be
imported so that the extra code to generate random elements is available to use.

2 Create the array containing the numbers 1 to 6. The numbers are stored as integers.

3 Set the input for the program to be when the micro:bit is shaken.

The input is indented


beneath the while
True code. This is to
ensure that the micro:bit
will react continuously to
the shake movement as
an input.

99
369825_9.3_Cam_LSC_SB_088-128.indd Page 100 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

4 The next step is to output a randomly generated item from the array to the
micro:bit display. There are two ways in which something can be displayed using
the micro:bit LEDs:
– display.show() is used for an integer, letter or image; if there is more than one digit
or image, they will be shown in sequence with a delay between each one
– display.scroll() is used for a string; the text will scroll across the screen.
When using display.show(), place the array name inside the brackets:

However, instead of a set index position being used inside the square brackets, a
random position needs to be generated. The array has six items, which means that the
positions are within a range of 0 to 5.
Position 0 1 2 3 4 5
Array item 1 2 3 4 5 6

The code to randomly generate a value between 0 and 5 – the known positions in this
array – is:

This is placed inside the square brackets to replace the position number:

5 To finish the program, a short delay is added to allow the number to be shown before
the display is cleared:

The program can now be sent to the micro:bit, and every time the micro:bit is shaken, a
random number between 1 and 6 is displayed.

100
369825_9.3_Cam_LSC_SB_088-128.indd Page 101 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

To test that a random number is being generated, you can create a test table to
document the output after each shake. An example is shown below.
Test number Output
1 5
2 1
3 5
4 3
5 4
6 2
7 4
8 6
9 4
10 6

Practise
1 A game such as a quiz requires the players to be placed in a group or team. Look at
the pseudocode below.
START
IMPORT random library

ARRAY groups = [Group 1, Group 2, Group 3, Group 4]

IF micro:bit is shaken THEN


OUTPUT a random item from groups
DELAY 500
OUTPUT clear screen
ENDIF
STOP
a How could this pseudocode help in selecting the group each person is in?

101
369825_9.3_Cam_LSC_SB_088-128.indd Page 102 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

b Discuss with your partner what is different about the pseudocode above compared
with the pseudocode below.
START
IMPORT random library

ARRAY numbers = 1, 2, 3, 4, 5, 6

IF micro:bit is shaken THEN


OUTPUT a random item from numbers
DELAY 500
ENDIF
STOP
2 Copy and complete this table to identify the item stored at each position of the array.
Position 0 1 2 3
Array item

3 Create a test plan for the pseudocode above using normal and invalid test data.

Test Input data Expected outcome Pass/fail


1 Normal
2

4 a Write the program code to match the pseudocode.


b Connect the micro:bit and send the program.
c Use your test plan from task 3 to make sure that your program is working correctly.
5 Create a table to test that the values generated are random, and use this to check the
outputs from your program.
Test number Output
1
2

6 Download the program to your computer and save it.


– Select the three vertical dots next to the Save icon.
– Select Save Python Script.
– Move it from the ‘Downloads’ folder to your own folder and save it as
randomGroupGenerator.py.
7 Discuss with your partner:
a where data is being stored and gathered in this program
b how a program to choose a random element from an array could be used in a game.

102
369825_9.3_Cam_LSC_SB_088-128.indd Page 103 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Count-controlled loops and the micro:bit

Learn
Look at this program. It has been created to output a section of a times table using the
micro:bit to display the answer. This example outputs the answer to 1 × 2, 2 × 2 and 3 × 2.

KEYWORD
trace table: technique for predicting
step by step what will happen as each
line of an algorithm or program is run,
and to identify errors

The program code above is repeated each time.


The program can be decomposed using a trace table.
l Lines 3, 4 and 5 – three variables are set up:
You explored trace tables
– ‘number’ storing the value 1 in Unit 9.1. Refer back to
– ‘times_table’ storing the value 2 that unit to recap how a
– ‘answer’ storing the value 0. trace table is structured.

Line Variable Variable Variable Output


number times_table answer
3 1
4 2
5 0

103
369825_9.3_Cam_LSC_SB_088-128.indd Page 104 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

l Line 7 – an equation (number * times _ table) updates the value stored in the
variable ‘answer’; the values stored in the variables make this equation 1 × 2, so the
answer 2 is stored in the variable ‘answer’.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2

l Line 8 – the value stored in the variable ‘answer’ is displayed on the micro:bit.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2

l Line 11 – the value stored in the variable ‘number’ is increased by 1.


Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2

l Line 12 – an equation (number * times _ table) updates the value stored in the
variable ‘answer’; the values stored in the variables make this equation 2 × 2, so the
answer 4 is stored in the variable ‘answer’.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2
12 4

104
369825_9.3_Cam_LSC_SB_088-128.indd Page 105 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

l Line 13 – the value stored in the variable ‘answer’ is displayed on the micro:bit.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2
12 4
13 4

l Line 16 – the value stored in the variable ‘number’ is increased by 1.


Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2
12 4
13 4
16 3

l Line 17 – an equation (number * times _ table) updates the value stored in the
variable ‘answer’; the values stored in the variables make this equation 3 × 2, so the
answer 6 is stored in the variable ‘answer’.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2
12 4
13 4
16 3
17 6

105
369825_9.3_Cam_LSC_SB_088-128.indd Page 106 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

l Line 18 – the value stored in the variable ‘answer’ is displayed on the micro:bit.
Line Variable Variable Variable Output
number times_table answer
3 1
4 2
5 0
7 2
8 2
11 2
12 4
13 4
16 3
17 6
18 6

The program allows the micro:bit to output the answers to 1 × 2, 2 × 2 and 3 × 2. The
program code is long, and sections are repeated. If you wanted to extend the program
to output more of the times table, you would need to repeat the lines of code below
the others. However, the program code can be reduced greatly by using a count-
controlled loop.

A count-controlled loop is a set of instructions or program code that is repeated a set


number of times. In programming, a count-controlled loop is written as a for loop. It
repeats a set of instructions for a set number of times.

The pseudocode below shows how a count-controlled loop, a for loop, can be used. In
this example, ‘number’ is a variable that keeps track of how many times the code has
repeated. This is known as the counter variable, and can be set to any variable name
you choose. Each run of the instructions inside the loop is called an iteration. The
counter variable begins with a value of 0 and increases by 1 every time the loop iterates
over the instructions. The end value is the number of times the loop needs to run.

1 START KEYWORDS
2 answer = 0 count-controlled loop: set of
3 times _ table = 2 instructions repeated a set number of
4 times
5 FOR number = 0 to 3 for loop: the Python or MicroPython
loop for a count-controlled loop
6 answer = number * times _ table
counter variable: variable that stores
7 OUTPUT answer the number of times an iteration has
8 DELAY 500 iterated
9 ENDFOR iterate/iterative/iteration: repeat/
10 STOP repeated/repetition

106
369825_9.3_Cam_LSC_SB_088-128.indd Page 107 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

This can be seen in the trace table below. The yellow and green shading highlights
each iteration of the loop. The line numbers are revisited with each iteration (lines 5, 6
and 7) and there are four iterations of the indented instructions.
Line Variable Variable Variable Output
number times_table answer
2 0
3 2
5 0
6 0
7 0
5 1
6 2
7 2
5 2
6 4
7 4
5 3
6 6
7 6

If you want to increase the output to include


additional numbers in the 2 times table, you just
need to adjust the end value of the for loop.

This pseudocode above is then developed in MicroPython for the micro:bit. In


MicroPython (and Python), range() is used to state how many times the code needs to
be repeated, which is four times in this example:

107
369825_9.3_Cam_LSC_SB_088-128.indd Page 108 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

A count-controlled loop can be used creatively on the micro:bit to output a countdown.


The micro:bit has a built-in buzzer that acts as a speaker for sounds that have been
programmed to be output. It can be used to generate music, sounds and speech.
In the pseudocode below, speech is used to output a countdown from 3 to 1 and then ‘Go’.

START
IMPORT speech library

FOR number = 3 to 1
OUTPUT speech number
DELAY 1000
ENDFOR
OUTPUT speech "Go"
STOP

To generate a verbal countdown, follow these steps.


1 First, import the ‘speech’ library:

2 So far, you have used a for loop that counts up to a set value. To count backwards,
the range needs to have a start and end point and be told to reduce the number by
1 each time.

Remember that Python will exit the loop


when the count variable matches the value for the
end of the range.

The table below breaks down the program code in range().


range ( 3 0 –1 )
Start of range End of range Reduce by 1 on
each iteration

3 In this program, the speech function of the buzzer is used to output the number for
each iteration. The speech aspect on the micro:bit can output only a string. The value
stored in the variable ‘number’ must therefore be converted, or cast, to a string for it to
be output.
l The structure of the code for the speech function is KEYWORD
speech.say(). cast: change the data
type of a variable
l The words to be displayed are placed inside the brackets.

108
369825_9.3_Cam_LSC_SB_088-128.indd Page 109 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

l To output the contents of the variable and convert it to a string, the code
str(number) is placed inside the brackets:

This will now take the value stored in the variable ‘number’, convert it from an
integer to a string and output it through the buzzer as speech.
l This code must be indented inside the for loop:

4 A delay is added after the speech to leave a gap of 1 second before the next number.
1 second is 1000 milliseconds and so this is the value added in the brackets of the sleep
function:

5 The final speech output will be ‘Go’. This is not part of the for loop and therefore it
should not be indented. It will be the next instruction to run once the iterations of the
count-controlled loop are completed:

109
369825_9.3_Cam_LSC_SB_088-128.indd Page 110 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 START
2 IMPORT speech library
3
4 ARRAY shoppingList = [bread, milk, chocolate]
5
6 OUTPUT speech "You need to buy"
7 DELAY 1000
8
9 FOR each item in ARRAY shoppingList
10 OUTPUT speech item KEYWORD
11 DELAY 1000 algorithm: step-by-step
instructions to solve a
12 ENDFOR
particular problem
13 STOP
1 a With your partner, predict the outcome of the pseudocode above.
b Explain how iteration has been used in this pseudocode.
c Copy and complete the trace table below to follow the variable and array outputs
through the algorithm.
Line Array Variable Output
shoppingList item
4
6
9
10
9
10
9
10

d Discuss with your partner how using a trace table can help to identify how data is
used in a program.
2 a Create the MicroPython program to match the pseudocode using a count-controlled
loop.
b Connect the micro:bit to the computer and send the program to the micro:bit.
c Test the program to make sure that the output is what you expected.
d Download the program to your computer and save it.
– Select the three vertical dots next to the Save icon.
– Select Save Python Script.
– Move it from the ‘Downloads’ folder to your own folder and save it as
shoppingList.py’.

110
369825_9.3_Cam_LSC_SB_088-128.indd Page 111 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

3 a Create a pseudocode algorithm containing a count-controlled loop to output


an array containing three words that could be used in a ‘What am I?’ game: for
example, ‘pilot’, ‘chef’ and ‘teacher’.
b Create the trace table to test your algorithm.
c Create the program code to match your pseudocode to include a count-controlled
loop and the use of speech on the micro:bit.
d Connect the micro:bit to the computer and send the program to the micro:bit.
e Save as professionsList.py.
f Test that your program works as expected by repeating the trace table you created
in task 3b.
g Compare and contrast programs with your partner. Discuss any differences and, if
there are any, which program is better suited to the task and why.

Creating a musical output


Learn
A lot of computer games have a musical element to them. This can act as an introduction or
be used to highlight when something has happened in the game, such as game over. Music
adds another layer to a game and provides the player with more of an interactive experience.
The micro:bit has a built-in buzzer that acts as a speaker for sounds that have been
programmed to be output. It can accept individual musical notes that can be output to
produce a musical sequence.
In the ‘Arrays and micro:bits’ section, you explored how an array can be used to store
more than one item. The stored items can be used to represent the notes of a musical
sequence. Each note is represented as a sequence of characters.
C 4 : 4
Note Octave Duration
The musical note How high or low the musical note is played; How long the note is held for; the higher
0 is the lowest and 8 is the highest the number, the longer the note

For example, these steps create an array to output the musical sequence for the
traditional song ‘Frère Jacques’.

1 The first line of notes is: C D E C. The octave remains the same at 4, KEYWORD
a midpoint note. The length of each note is also 4. This needs only character:
to be set on the first note and the program remembers this for each single letter,
note that follows until it is told to change: digit or
symbol
C4:4, D4, E4, C4
2 Each of these notes now needs to be placed inside quotation marks:
"C4:4", "D4", "E4", "C4"
3 This line of notes can now be placed inside the square brackets with
the name of the array:
line1 = ["C4:4", "D4", "E4", "C4"]

111
369825_9.3_Cam_LSC_SB_088-128.indd Page 112 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

4 Follow these steps to output this array using the buzzer on the micro:bit.
a First you need to ensure that you have imported the music library. You must do
this at the start of the program, after the importing the micro:bit library:
from microbit import *
import music
b Add the code to program an output to the buzzer:
music.play()
c Add the name of the array inside the brackets. This now says to run the contents
of the array through the buzzer:
music.play(line1)

d This will output the line once. However, the line is repeated in the song. You could
write this by adding the same line again:

e But this is not an efficient way of adding and running code. You can use a count-
controlled loop to repeat the same line a set number of times:

112
369825_9.3_Cam_LSC_SB_088-128.indd Page 113 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

5 You can use a trace table to see how this program is using the array when it is run.
The counter variable will start at 0 and will change to 1 for the second iteration, for
example:
Line Array Variable Output
line1 counter
4 "C4:4", "D4", "E4", "C4"
6 0
7 "C4:4", "D4", "E4", "C4"
6 1
7 "C4:4", "D4", "E4", "C4"

6 You can create the next line of the song in the same way. You can use an array to
store the individual notes as items. This time, the last note needs to be longer than
the other two notes. Therefore, you need to add (:8) to the end of the note to tell
the program to double the length of the note:
"E4:4", "F4", "G4:8"
7 You can then create the program in the same way as before, with the array at the
start and a new for loop following the first:

On the next page is a trace table for the array and the two for loops. The line
numbers help to identify which count-controlled loop is being run.

113
369825_9.3_Cam_LSC_SB_088-128.indd Page 114 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Line Array Array Variable Output


line1 line2 counter
4 "C4:4", "D4", "E4", "C4"
5 "E4:4", "F4", "G4:8"
7 0
8 "C4:4", "D4", "E4", "C4"
7 1
8 "C4:4", "D4", "E4", "C4"
10 0
11 "E4:4", "F4", "G4:8"
10 1
11 "E4:4", "F4", "G4:8"

8 Once the program executes the first for loop on lines 7–8 in the
KEYWORD
code above, the program will continue to the second for loop
execute: carry out
on lines 10–11. It is important to set up the arrays at the start of the instructions
the program for the musical notes and then add the sequence described in a
of for loops to represent the musical output sequence required computer program
to play the song correctly.

Practise
1 With your partner, predict the outcome of the pseudocode below. Do array ‘line1’ and
‘line2’ look familiar?
1 START
2
3 ARRAY line1 = [C4:4, D4, E4, C4]
4 ARRAY line2 = [E4:4, F4, G4:8]
5 ARRAY line3 = [G4:2, A4, G4, F4, E4:4, C4]
6 ARRAY line4 = [C4:4, G3, C4:8]
7
8 FOR i = 0 to 1
9 OUTPUT line1 to buzzer
10 ENDFOR
11
12 FOR i = 0 to 1
13 OUTPUT line2 to buzzer
14 ENDFOR
15
16 FOR i = 0 to 1

114
369825_9.3_Cam_LSC_SB_088-128.indd Page 115 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

17 OUTPUT line3 to buzzer


18 ENDFOR
19
20 FOR i = 0 to 1
21 OUTPUT line4 to buzzer
22 ENDFOR
23 STOP
2 Create a trace table to check the flow of the variables and array outputs through the
program.
3 Discuss with your partner how data is stored and used in this program.
4 a Create the MicroPython program to match the pseudocode.
b Connect the micro:bit to the computer with
the USB cable and send the program to the Remember to use
micro:bit. count-controlled loops in the
c Test that the program output is as expected. right sequence to create the
Does the output match the musical sequence correct musical output.
you expect?
d Download the program to your computer
and save it.
– Select the three vertical dots next to the Save icon.
– Select Save Python Script.
– Move it from the ‘Downloads’ folder to your own folder and save as
frereJacquesComplete.py.
5 a Create the pseudocode to output the tune ‘Happy Birthday’ twice using this musical
sequence.
Happy birthday to you G3:2, G3, A3:4, G3, C4, B3
Happy birthday to you G3:2, G3, A3:4, G3, D4, C4
Happy birthday dear name G3:2, G3, G4:4, E4, C4, B3, A3
Happy birthday to you F4:2, F4, E:4, C4, D4, C4

b Create the program code to match your pseudocode. Save as


happyBirthdayComplete.py.
c Connect the micro:bit to the computer and
send the program to the micro:bit. Test Remember to use count-
whether the output is what you expect from controlled loops to iterate over
your knowledge of the tune. an array to repeat an array or
sequence of arrays.

115
369825_9.3_Cam_LSC_SB_088-128.indd Page 116 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Arrays, loops and selection


Learn
In the previous themes, you explored using an array to store integers and strings. An array
on the micro:bit can also store images.
There is a set of predefined images that can be used on the micro:bit. In this example, the
animal ones will be used:
DUCK TORTOISE BUTTERFLY GIRAFFE SNAKE

The MicroPython syntax to display an image is:

To edit the image displayed, HEART is replaced with one of the predefined images in
uppercase letters:

The following example of a guess-the-animal game using images has been planned using
pseudocode.
1 START
2 IMPORT random library
3 IMPORT music library
4
5 ARRAY images = [DUCK, TORTOISE, BUTTERFLY, GIRAFFE, SNAKE]
6 ARRAY correctTune = [G4:1, C5, E, G:2, E:1, G:3]
7
8 IF button A is pressed THEN
9 OUTPUT random image from ARRAY images
10 ENDIF
11
12 IF button B is pressed THEN
13 OUTPUT correctTune
14 DELAY 500
15 OUTPUT clear screen
16 ENDIF
17
18 STOP
l Two arrays have been set up: ‘images’ and ‘correctTune’.
– ‘images’ stores the list of possible images.
– ‘correctTune’ stores the notes to play a tune when the user guesses correctly.
l When the A button is pressed, a random image is displayed on the micro:bit.
l When the B button is pressed, a celebration musical sequence is played, and after 500
milliseconds the display is cleared.

116
369825_9.3_Cam_LSC_SB_088-128.indd Page 117 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

A trace table can be used to follow the data that is being used in this algorithm. It can
help to find any errors that may have occurred while writing the program, for example, an
incorrect or misspelt array name.
Line Array Array Condition Condition Output
images correctTune A button = True B button = True
5 DUCK, TORTOISE,
BUTTERFLY,
GIRAFFE, SNAKE
6 G4:1, C5, E, G:2, E:1, G:3
8 True
9 One array image
12 True
13 correctTune
15 Clear screen

The pseudocode can be used to create the program by following these steps.

1 To use ‘random’ and ‘music’ in the program, you first need to import both the
‘random’ and ‘music’ libraries:

2 You need to create the array to store the images. As the array is going to store the
images that can be displayed, you need to use the correct syntax for the array items.
An image is defined in the program as Image.DUCK, so this is the correct format to
use for each list item:

3 Create the array to store the celebration musical sequence. The notes and sequence
have been set as "G4:1", "C5", "E", "G:2", "E:1", "G:3".

117
369825_9.3_Cam_LSC_SB_088-128.indd Page 118 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

4 IF the A button is pressed, THEN the program should display a random image.
There is a function that allows the program to choose an item randomly from
the list: random.choice(). The array name is placed inside the brackets: random.
choice(images).
To output a random image, place this function inside the brackets of the code to
output an image to the micro:bit display: display.show(random.choice(images)).

This code is indented below while True: to ensure that the micro:bit continuously
reacts if the button is pressed.
5 IF the B button is pressed, THEN the program should play the celebration musical
sequence, wait and then clear the screen.

Once a program has been written, it is important to test it. If the program involves a
random element, this should be reflected in the test plan.
The normal test data would be the expected inputs to the program. In this program,
the A button is tested more than once to check that a randomly generated image is
displayed each time.
The invalid test data would be any other input on the micro:bit to ensure that it does
not activate any element of the program.

KEYWORD
function: sub-program that can exist as part of a bigger program

118
369825_9.3_Cam_LSC_SB_088-128.indd Page 119 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Test Input data Expected outcome Pass/fail


Normal A button pressed Random image displayed Pass – tortoise
Normal A button pressed Random image displayed Pass – giraffe
Normal A button pressed Random image displayed Pass – snake
Normal A button pressed Random image displayed Pass – tortoise
Normal A button pressed Random image displayed Pass – giraffe
Normal A button pressed Random image displayed Pass – duck
Normal A button pressed Random image displayed Pass – duck
Normal A button pressed Random image displayed Pass – giraffe
Normal A button pressed Random image displayed Pass – butterfly
Normal B button pressed Celebration musical sequence plays Pass
Wait 500
Clear screen
Invalid Shake micro:bit Nothing Pass

Practise
1 START
2 IMPORT random library
3 IMPORT music library
4
5 ARRAY images = [CLOCK 12, CLOCK 1, CLOCK 2, CLOCK 3, CLOCK 4,
CLOCK 5, CLOCK 6, CLOCK 7, CLOCK 8, CLOCK 9, CLOCK 10, CLOCK 11]
6 ARRAY correctTune = [G4:1, C5, E, G:2, E:1, G:3]
7
8 score = 0
9
10 IF button A is pressed THEN
11 OUTPUT random image from ARRAY images
12 ENDIF
13
14 IF button B is pressed THEN
15 OUTPUT images
16 score = score + 1

119
369825_9.3_Cam_LSC_SB_088-128.indd Page 120 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

17 DELAY 500
18 OUTPUT clear screen
19 ENDIF
20
21 IF micro:bit is shaken THEN
22 OUTPUT score
23 DELAY 1000
24 score = 0
25 ENDIF
26
27 STOP
1 With your partner, predict what the pseudocode above will do.
2 a ‘correctTune’ should play if the B button is pressed. Rewrite this part of the
pseudocode correctly.
b Check the pseudocode using a new trace table.
3 Discuss with your partner how data is stored and used in this program.
4 Create a test plan using normal and invalid test data.
5 a Create the MicroPython program to match the pseudocode.
b Connect the micro:bit to the computer with the USB cable and send the program to
the micro:bit.
c Test the program using your test plan, to make sure that the output is as expected.
d Download the program to your computer and save it as clockfaceGuessingGame.py.

Go further
Remember: Development of a program is done in iterations. The program is written,
tested and reviewed and, at this point, potential improvements may be identified. A new
iteration of the program is then developed, tested and reviewed. It is important to save
each iteration as a new version of the program. If you save over the previous version, you
will not have the original to go back to if the new additions do not work. This is called
version control. It allows the programmer to track the changes that have been made
through the different development iterations.
In the previous section, you created a program that used KEYWORD
the predefined images available on the micro:bit. You can version control: saving
each development
also create your own images. Each individual LED light on
iteration as a new
the micro:bit can be used to create a unique image. You filename to track
can switch a light on using the number 9 and off with the changes
number 0.

120
369825_9.3_Cam_LSC_SB_088-128.indd Page 121 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

For example, you can create a question mark and add this to the array, using a 5 × 5
grid to plan the image. Each square on the grid represents an individual LED light on the
micro:bit.

You must place the code for the new image near the top of the program, after the arrays
have been created. The pseudocode below shows that the numbers for the image are
placed in a grid style too. This is to ensure that the right numbers are added in the
correct positions. You can enter them on a single line with each number separated by a
comma, but this makes it harder to check the image layout.
START
IMPORT random library
IMPORT music library

ARRAY images = [DUCK, TORTOISE, BUTTERFLY, GIRAFFE, SNAKE]


ARRAY correctTune = [G4:1, C5, E, G:2, E:1, G:3]

questionMark = 09990
00090
00990
00000
00900

ADD questionMark to ARRAY images

121
369825_9.3_Cam_LSC_SB_088-128.indd Page 122 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

IF button A is pressed THEN


OUTPUT random image from ARRAY images
ENDIF

IF button B is pressed THEN


OUTPUT correctTune
DELAY 500
OUTPUT clear screen
ENDIF

STOP

A new image can be created by following these steps.


1 a Create a variable to store the new image: questionMark =
b Image() is required after the equals sign ( = ) to tell the program that the data
that follows is a new image.
c Each LED in the line is represented using a 0 or 9: for example, the first line of
the question mark image would be "09990:". The quotation marks and colon are
important aspects of the syntax and must be replicated on each line:

2 To add this new image to the array, you need to use the append() function:

122
369825_9.3_Cam_LSC_SB_088-128.indd Page 123 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

3 The program will now have a question mark added to the array and this will be a
possible output when the A button is pressed.

1 a Create a 5 × 5 grid and plan a new animal image.


b Create the pseudocode for your new animal image.
2 Discuss with your partner the challenges of creating You will need to create a
an image of an animal on the micro:bit display. new variable to store
3 Create a test plan using normal and invalid test data. the image and add it to
a Create the program to match the pseudocode. the array.
b Connect the micro:bit to the computer with the USB
cable and send the program to the micro:bit.
c Test the program using the test plan you have just set up to make sure it gives the
output that you expect.
d Download the program to your computer and save it as a new iteration.

123
369825_9.3_Cam_LSC_SB_088-128.indd Page 124 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Challenge yourself
A game often has a time limit. In a guessing game, the player may have 60 seconds to
guess as many of the images displayed as possible. Using a second micro:bit allows a
player to start a timer once the other player begins their guesses.
When you are using a count-controlled loop, you can use selection to check a variable
each time a loop is run. The code to be run as part of the selection statement is indented
another layer within the for loop. Where one programming construct, such as selection,
occurs inside another construct, such as a count-controlled loop, this is known as nesting.
In the example below, each iteration reduces the value stored in the variable ‘time’ by 1.
On each iteration, the value is tested to see whether it meets the conditional statement,
which is to see whether it is equal to 0.
l If the outcome is False, then the next iteration continues.
l If the outcome is True, then an ‘X’ is displayed on the micro:bit.

KEYWORDS
selection: choice to be
added to a program using
if… elif… else and the
next instruction executed in
the program is decided by
the outcome of a condition
nesting: one programming
construct, e.g. selection,
occurring inside another
construct, e.g. a count-
controlled loop

You can use a trace table to see the values of the variables and the outputs as the
program iterates through each run of the code in the loop.
Line Variable Variable Condition Output
time i time == 0
3 3
4 3
6 0
7 2
8 2
9 False
6 1
7 1
8 1
9 False

124
369825_9.3_Cam_LSC_SB_088-128.indd Page 125 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Line Variable Variable Condition Output


time i time == 0
6 2
7 0
8 0
9 True
10 X displayed

The next development iteration uses a second micro:bit. The second micro:bit acts as
the timer for the game. The countdown needs to go from 30 to 0, and when it gets to 0
an X should be displayed, along with a musical sequence or text output using speech to
represent the end of the game.
1 Plan the algorithm for the second micro:bit program in pseudocode. Your algorithm
should use speech, time, a count-controlled loop and nested selection, and you should
also consider how the timer is activated.
2 Create a trace table and test the flow through the pseudocode.
3 Create a test plan using normal and invalid test data and include extreme test data to
check the start and end countdown displayed.
4 a Create the program code to match the pseudocode.
b Connect the micro:bit to the computer with the USB cable and send the program to
the micro:bit.
c Use the test plan to check that the program output is what you expected.
d Download the program to your computer and save it as countdownTimer.py.

Final project
The skills you have learned in this unit are all about using arrays, count-controlled
loops and new functions on the micro:bit. You have developed some of the programs
iteratively to create new outputs for the micro:bit. You have learned how to trace a
variable or array through pseudocode or a program using a trace table and how using
music and speech can enhance a game.
Look back to the start of this unit to remind yourself of the KEYWORD
Scenario. You now have all the skills and knowledge to follow criteria: set of rules
the criteria to create your own program for the ‘What am ?' that must be met
game.

125
369825_9.3_Cam_LSC_SB_088-128.indd Page 126 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

KEYWORDS
The game should:
l display an item from a pre-set list to the player
data type: classification
applied to a data item
randomly specifying which type of
l use an input either through the accelerometer or a data that item represents,
button to represent when the player has correctly e.g. in a spreadsheet some
guessed, and play a tune to represent a correct of the data types available
answer include currency, text and
number
l reset through another input, to start the game again
l use speech, music and images within the game
prototype: initial product
created for testing and
l utilise a count-controlled loop, selection, array and
reviewing, before a final
variables product is released
l use a time delay to aid gameplay.

Complete the tasks below.


Part 1: Planning
Before you start to write the code:
1 Using a table, plan the variables, arrays and data types you are going to use in your
program.
2 Identify the micro:bit inputs and outputs you are going to use in the game.
3 Identify the libraries you need to import at the start of the program.
4 Plan the algorithm by creating the pseudocode to match the Scenario.
5 Create a trace table to follow the flow of the arrays and variables you use.
6 If necessary, iteratively develop and test the pseudocode until it is ready for you to
develop into program code.
7 Make a note of any changes you have made through iterative development of the
pseudocode.
Part 2: Development
When you are sure that the pseudocode algorithm is complete and correct, start the
development of the MicroPython code.
1 Create a test plan to use at different stages of development, and consider normal
and invalid test data.
2 Continuously develop, test, debug and improve your prototype program code.
3 Save each development as a new iteration of the prototype program.
Part 3: Project summary
Once you have created, tested and evaluated your program solution:
1 List the different development iterations that the program has gone through to
develop your final program code.
2 Use word-processing software to write a paragraph evaluating the process of
iteratively developing the program code and saving each iteration.
3 Write a short report to describe how the game is played and how the micro:bit
enhances the gameplay.

126
369825_9.3_Cam_LSC_SB_088-128.indd Page 127 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

Unit 9.3 Coding and testing: Game development for the micro:bit

Evaluation

Part 1: Planning
Swap planning documents (planning table, pseudocode and trace table) with your
partner. Discuss the following:
1 Are all variables and arrays planned using a structured table?
2 Does the pseudocode use a count-controlled loop, array, speech, micro:bit inputs and
musical and image outputs?
3 Does the pseudocode show the use of a time delay?
4 Does the trace table show the correct flow of the array outputs and variables through
the algorithm?

Part 2: Development
Swap programs with your partner. Discuss the following:
1 Does the program randomly generate an item from the array?
2 Does the program use a count-controlled loop?
3 Does the program use speech, music and images?

Part 3: Project summary


Swap reports with your partner. Discuss the following:
1 Are the program development iterations listed?
2 Has your partner evaluated the process of developing a program iteratively to show
what is good and what is not so good?
3 Does the report include a how-to guide to help a player play the game using the
micro:bit?
4 a Open your own program and look at the code. Reflect on what could be improved
in your own program following your partner’s feedback.
b Based on the evaluations, make the changes to improve your final program.

What can you do?

Read and review what you can do.


✓ I can follow, understand, edit and correct algorithms that are presented as
pseudocode.
✓ I can follow flowchart or pseudocode algorithms that use loops.
✓ I can create algorithms using flowcharts and pseudocode.
✓ I can explain and use iteration statements with count-controlled loops in either
pseudocode or flowcharts.
✓ I can predict the outcome of algorithms that use iteration.
✓ I can compare and contrast two algorithms for the same solution and decide which
is best suited to a task.
✓ I can create an algorithm as a flowchart or pseudocode using more than one
construct: sequence, selection and count-controlled iteration.

127
369825_9.3_Cam_LSC_SB_088-128.indd Page 128 06/03/23 9:50 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

✓ I can identify and explain the purpose of a one-dimensional array.


✓ I can identify and describe data types in MicroPython programs, including integer,
real, character, string and Boolean.
✓ I can develop MicroPython programs with count-controlled loops.
✓ I can access data from an array using MicroPython.
✓ I can use iterative development on micro:bit prototypes to create solutions to
problems.
✓ I can evaluate the processes that are followed to develop programs.
✓ I can develop and apply test plans that include normal, extreme and invalid data.
✓ I can identify test data that covers normal, extreme and invalid data.
✓ I can use a trace table to check the flow of a variable or array through an algorithm.
✓ I can program a micro:bit to use data to solve a problem.

128
369825_9.4_Cam_LSC_SB_129-159.indd Page 129 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

Unit Drilling down: How the


9.4 processor handles instructions

Get started!
Have you ever thought about the different ways in
which we, as users, are able to gain access to the
many digital devices we use in our daily lives?
Discuss the following with your partner:
● How do you gain access to a digital device to be
able to start using it?
● What do you need to do to complete a task using
the device, for example sending a message or an
email to a friend?
● How does the device know what to do when you click on a particular icon or select an
option on screen?
In this unit, you will learn more about the software in digital devices that allows users
to operate and manage the devices appropriately: applications software and systems
software. You will look in more detail at how the processor executes computer
programs in digital devices. You will develop your knowledge of logic gates to help
you to understand how devices use logic gates to store data and how they can be
combined to carry out tasks described by computer programs. You will examine
programs that use machine learning, and you will consider how machine learning
and computerisation have helped to improve the way in which tasks are completed in
various manufacturing scenarios.

KEYWORDS
software: program or set of instructions that tell a often called the central processor or central
computer what to do to complete a task; aspects processing unit
of a device you cannot touch execute: carry out the instructions described in a
applications software: software designed to do a computer program
particular task, e.g. a word processor, spreadsheet, program: instructions that tell a computer system
web browser, mobile-phone app how to complete a task
systems software: software that helps a user run a data: raw facts and figures
computer
machine learning: ability of a computer system to
processor: electronic circuitry that executes the learn over time
instructions described in a computer program;

129
369825_9.4_Cam_LSC_SB_129-159.indd Page 130 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Learning outcomes
In this unit, you will learn to:
● identify improvements to the design of digital devices based on prototypes
● explain why factors such as user experience, accessibility, ergonomics and emerging
technologies are important to the design of digital devices
● explain which tasks an operating system carries out
● describe examples of utility programs, including drivers, security software and
defragmentation
● explain the different types of translator
● describe the main characteristics of compilers and interpreters
● explain how analogue sound is digitised
● explain how to convert between storage units
● draw logic circuits for Boolean expressions
● explain how computers store lists of instructions to be run one at a time
● explain the fetch–decode–execute cycle
● describe what is meant by machine learning and identify a range of applications and
scenarios where machine learning is used
● explain the benefits and risks of computerising tasks in industry and manufacturing.

Warm up
1 In pairs, think about all the digital
devices you have access to on a daily
basis.
2 Write down the names of some of the
software you use on each device. Most
devices may have more than one piece
of software installed. Beside each piece
of software, write down the task you use
it for.
3 Review your list of software and think
about all the tasks you complete using
the device. Have you included all tasks,
such as logging on to the device, organising files on the device, creating new accounts
on the device?

SCENARIO
A new computing technology company promoting student interest in the computing industry
is delivering a workshop for Stage 9 students to increase understanding of how computing
technology and machine learning are used in industry and home technologies.
Your task is to help the company to prepare for the workshop. You will need to create resources
(a presentation, worksheets, a poster and a prototype design) that can be used to explain the
technologies to students.

130
369825_9.4_Cam_LSC_SB_129-159.indd Page 131 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

The resources you are tasked with developing need to cover the following areas:
l Information about how an operating system carries out tasks
l Examples of utility programs, including drivers, security software and
defragmentation
l Why different types of translators are needed to convert computer programs into a
form the processor can understand
l A description of the main characteristics of compilers and interpreters
l How analogue sound is digitised
l How to convert between storage units used to measure the size of data files
l How to draw logic circuits for Boolean expressions
l How computers store lists of instructions to be run one at a time
l What the fetch–decode–execute cycle does
l The meaning of machine learning and a range of scenarios where machine learning is used
l The benefits and risks of the computerisation of traditional manufacturing and
industrial practices
l How prototypes can be used to identify areas where the design of digital devices can
be improved.

KEYWORDS
prototype: initial product created for testing and interpreter: translates each line of high-level
reviewing, before a final product is released language code into machine code
operating system: software that manages all the analogue: continually varying signal, e.g. a sound
computer hardware and software; it also acts signal
as an interface between computer hardware digitise: convert into digital format, i.e. into 1s and
components and the user, and provides a platform 0s
where applications can run
convert: change from one unit to another, e.g.
device driver: software program that operates a storage units (e.g. bits/bytes/kilobytes)
hardware device connected to a computer
storage units: number of bits used to store a data
security software: any type of software that item in a digital device
secures and protects a digital device
logic circuit: combination of logic gates for solving
defragmentation: reorganising files stored on a a problem in a digital device
hard drive to ensure that all parts of the same file
list: data structure in Python that can store
are located one after the other on the drive
multiple items of data of mixed data types under a
translator: converts program instructions into single identifier; data items can be changed
machine-code format so the processor can carry
traditional manufacturing: the making of products
out the instructions
before computerisation; it often relied on human
compiler: translates an entire computer program production lines, where people completed
into machine code and creates a file containing individual tasks, which were passed along the
machine code for the entire program production line until the final product was
complete

131
369825_9.4_Cam_LSC_SB_129-159.indd Page 132 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Do you remember?
Before starting this unit, you should be able to:
✔ describe the differences between applications software and systems software
✔ explain that the operating system is an example of systems software
✔ explain the role of utility programs in a computer system
✔ explain that data and programs that are to be reused are stored in secondary storage
devices such as a hard disc drive
✔ explain that ASCII is a set of binary codes that can represent the character set of a
digital device
✔ explain that data such as sound can be represented in digital format
✔ explain the role of logic gates in circuits, including AND, OR and NOT gates
✔ draw the symbols that represent AND, OR and NOT gates in a logic circuit
✔ describe how AND, OR and NOT gates operate
✔ identify text-based programming languages, such as Python
✔ explain what is meant by the term machine learning and identify applications where
machine learning is used.

Understanding software
Learn
Digital devices use a number of different types of software to complete a task. To recap,
the software available on any digital device can be divided into two broad categories:
applications software and systems software; systems software in turn can be broken
down into the operating system and utilities software.

Software

Applications software Systems software


Software designed to do a Software that manages
particular task, e.g. a word all the hardware and
processor, spreadsheet, web applications software
browser, mobile-phone app available on a digital device

Operating system Utilities software


Acts as an interface between Software that helps maintain
computer hardware components the smooth functioning of a
and the user and provides a digital device by helping the
platform where applications operating system manage tasks
can run and resources

132
369825_9.4_Cam_LSC_SB_129-159.indd Page 133 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

The operating system is a key part of any digital device. Without the operating system,
the user would not be able to interact with the device and other programs could not run
on the device. The operating system has a number of key tasks. It:
● manages the hardware of the device, including the processor
● runs applications
● provides an interface for the user to interact with the device
● manages the storage and retrieval of files.

The operating system cannot guarantee the smooth operation of a digital device on its
own. Utility programs also have an important role to play. Some examples of important
utility programs (sometimes known as tools) include: device drivers, security software
and defragmentation programs.

Device driver
This is a software program that operates a hardware device connected to a computer.
Device drivers are essential for a computer to work properly. Many devices are now
known as plug-and-play devices. This means that the device is automatically detected
and set up correctly for use by the operating system. No human intervention is needed.
Security software
When considering security software, most people
think about the software used to limit access to
digital devices: for example, the use of passwords
or personal identification numbers (PINs). Some
devices even use biometric security methods such
as facial recognition, fingerprint recognition or
voice-pattern recognition.

In fact, any type of software that secures and protects a digital


device is an example of security software, including:
● firewalls
● antivirus
● anti-spyware
● anti-malware.

All these features and all the tasks you carry out using a digital device are possible
only because of the software you have installed on the device.
Disc defragmenter
When you save a file on your digital device, you should give the file a relevant filename.
The operating system uses an algorithm to decide where on the hard drive the file
is to be saved. This can lead to pieces of files being stored in different places on the
hard drive, which is called fragmentation. It means that when you try to open that file,
the operating system has to spend a lot of time locating all the parts of the file and
reassembling them correctly in Random Access Memory (RAM).

133
369825_9.4_Cam_LSC_SB_129-159.indd Page 134 06/03/23 9:51 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

You can use the defragmentation utility tool to reorganise the data on the disc so
that all parts of the same file are stored together. The diagram below shows what the
surface of a disc looks like before defragmentation takes place. A file may be stored
in different portions of a hard disc surface. After defragmentation, the disc surface is
reorganised so that all the data relating to a file is stored beside each other on the disc
surface. This makes the data easier to access.

Before defragmentation, a file


may be stored in different portions of a
hard disc surface. After defragmentation, the
disc surface is reorganised so that all the data
relating to a file is stored beside each other
on the disc surface. This makes the
Before defragmentation After defragmentation data easier to access.

KEYWORDS
applications software: software designed to do a password: code made up of numbers or numbers
particular task, e.g. a word processor, spreadsheet, and letters and other characters (depending on the
web browser, mobile-phone app device), which allows a user access to a digital device
systems software: software that helps a user run a biometric security: security method that identifies
computer people using a physical attribute (e.g. a fingerprint)
operating system: software that manages all the or a behaviour (e.g. a hand gesture)
computer hardware and software; it also acts facial recognition: system that matches a real-time
as an interface between computer hardware image of a human face with a database of saved
components and the user, and provides a platform facial representations to allow a user access to a
where applications can run digital device
utilities software: software that helps maintain the fingerprint recognition: system that matches a real-
smooth functioning of a digital device by helping the time image of a human fingerprint with a database
operating system manage tasks and resources of saved fingerprint representations to allow a user
hardware: physical parts of a computer that you access to a digital device
can touch and see, e.g. the processor, storage voice-pattern recognition: software that can
devices, input devices, output devices understand and carry out spoken instructions
device driver: software program that operates a algorithm: step-by-step instructions to solve a
hardware device connected to a computer particular problem
security software: any type of software that hard disc drive: removable disc in computers for
secures and protects a digital device storing large amounts of data, typically measured
defragmentation: reorganising files stored on a in gigabytes or terabytes
hard drive to ensure that all parts of the same file fragmentation: situation that occurs when pieces
are located one after the other on the drive of files are scattered across the surface of a hard
plug-and-play device: device that is detected disc when the operating system is storing the file
automatically and set up correctly for use by the Random Access Memory (RAM): memory used to
operating system; no human intervention is needed store programs and data currently being used by
personal identification number (PIN): sometimes the processor
called a PIN number or PIN code; a numerical
passcode that allows a user access to a digital device

134
369825_9.4_Cam_LSC_SB_129-159.indd Page 135 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Practise
Your teacher may provide you with a file called Systems Software Presentation.pptx
to help you complete the following tasks.
1 List three examples of operating systems.
2 List five examples of applications software.
3 Use the internet to research the tasks that the following utility programs carry out.
a Disc management tools
b Compression tools Remember to
c Disc clean-up tools describe the role of
d File-management systems each utility program
e Backup utilities and security
software tool you
4 Research the roles played by the following examples
have researched.
of security software.
a Firewalls c Anti-spyware
b Antivirus d Anti-malware
5 Summarise your findings from tasks 3 and 4 in a short report or presentation.
6 Discuss with your partner the meaning of the term fragmentation and explain the
role of disc-defragmentation programs. Make short notes on the outcome of your
discussion. You may wish to record your notes on a new slide in your copy of the file
Systems Software Presentation.pptx.

Digitising sound
Learn
All programs and data stored inside a digital device are stored in binary format; this
includes the operating system and utility programs. Security programs, such as the
biometric login security applications on digital devices, store details about users’ facial
representations or fingerprints, or even voice patterns, in digital formats. You have
previously considered how images can be digitised, but what about applications that
need to store sound in digital format?
Today, most digital devices accept input from users
via microphones in the form of spoken words.
Sound waves create what is called an analogue
sound wave, such as the one shown on the right.
Computers do not store data in analogue format so the sound wave must be converted
into digital format. Converting analogue signals into digital is carried out by a device
called an analogue-to-digital convertor (ADC).

www.africanews.com

ADC DAC

Sound input into a digital device Before a sound can be output from a digital
must be converted from analogue device, it must be converted from digital
to digital format. This task is carried format back into an analogue signal. This
out by an analogue-to-digital task is carried out by a digital-to-analogue
converter (ADC). converter (DAC).

135
369825_9.4_Cam_LSC_SB_129-159.indd Page 136 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

ADCs take samples of the sound wave at fixed intervals in time; this process is called
sampling. The number of samples taken each second is called the sample rate. The
sample rate is measured in number of times per second, which is known as hertz (Hz). So,
for example, if the sample rate were 1 Hz, this would mean that only one sample was taken
per second. The diagram below shows an analogue sound wave that has been sampled
twenty times in 1 second.

Sample 2 Sample 3

111
110 Analogue input
Binary values

101 Digital output


100 Sample 20
011
010
001 20 samples have
000 been taken in one
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 second here, so the
Time sample rate is 20 Hz.

Sample 1

Each sample is represented by binary digits (in this case three) using the values
on the y-axis of the graph (‘Binary values’), for example:
● Sample 1 = 100
● Sample 2 = 101
● Sample 3 = 110

… and so on, up to:


● Sample 20 = 011.

In the example above, 3 bits are used to store each sound sample. The number of bits used
to store each sound sample is called the bit depth. The more samples taken, and the more
bits used to record each sound sample, the better the quality of the digital sound file.

KEYWORDS
analogue: continually varying signal, e.g. a sound hertz (Hz): unit of measurement of how many
signal sound samples are taken in 1 second
analogue-to-digital converter (ADC): converts binary digit: 0 or 1; the smallest unit of binary data
analogue signals, e.g. the human voice, to digital represented on a digital device
signals
bit: short for ‘binary digit’: 0 or 1
sampling: taking samples of a sound wave at fixed
bit depth: the number of bits used to store a single
intervals
sound sample
sample rate: number of sound samples taken each
second

DID YOU KNOW?


Devices such as microphones and speakers come with a device driver (a utility program)
that has to be installed onto the digital device they are being used with. This helps to
ensure that the device can communicate correctly with the processor in the digital device.

136
369825_9.4_Cam_LSC_SB_129-159.indd Page 137 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Practise
1 Write a short paragraph explaining how
For example, look at the sample taken at time
analogue sound is converted into digital
0 = 10, the sample taken at time 0.1 = 10 and
format.
the sample taken at time 0.2 = 11. Where
2 Use sampling to convert the sound wave would the red line that represents the binary
below into digital format. The sample rate sound sample be at time 0.3, 0.4, 0.5?
is 10 Hz.
11

10
Binary values

01

00
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (seconds)

3 The sample above was recorded using only 2 bits (a bit depth of 2).
a Try sampling the same sound wave using 4 bits (a bit depth of 4).
1101
1100
1011
1010
1001
Binary values

1000
0111
0110
0101
0100
0011
0010
0001
0000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (seconds)

b How does this 4-bit sample compare with


the previous 2-bit sample? For example, the sample
4 a Which sound sample would create the best- at time 0 = 0110, the sample
quality sound file? taken at time 0.1 = 1010. Complete
b Which bit depth would you recommend and the sample by noting the binary
pattern used and writing down
why?
the sound sample at the remaining
c Which sound sample would create the largest time intervals shown in the
file? Give a reason for your answer. diagram.

137
369825_9.4_Cam_LSC_SB_129-159.indd Page 138 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Data storage
Learn
All programs and data stored inside a digital device are stored in binary format; this includes
the operating system, utility programs and even data that is associated with a biometric
security system, for example, the sound pattern represented in the previous ‘Learn’ box.
A single binary digit (1 or 0) stored inside a digital device is known as a bit. In Stage 8,
you learned that special switches called transistors are used to represent each binary
digit inside a digital device. When data is stored inside a computer, the bits used to
represent the data can be grouped together and processed in larger units, shown in the
diagram below.

Petabyte (PB) = 1000 terabytes You may recognise some


of the terms in the diagram; you
Terabyte (TB) = 1000 gigabytes use them to describe the size
of a file.
Gigabyte (GB) = 1000 megabytes

Megabyte (MB) = 1000 kilobytes

Kilobyte (KB) = 1000 bytes

Byte = 8 bits
Eight bits grouped together is called a
byte, which can be used in computers to
Nibble = 4 bits represent a single character of text: for
example, 01000001 represents the letter
Bit = 1 or 0 (single binary digit) ‘A’ in most computer systems.

When saving a file, it is important to know whether there is enough space in an area of
memory or on the storage device to store the file. To do this, you need to be able to
convert between one storage unit and another.
To help you to complete this task, it is important that you remember the name of each
unit and the order in which the units appear. By multiplying or dividing repeatedly by
1000, it is easy to convert a file size from one unit into another, as shown below.

To convert from a smaller unit to a larger unit of storage:

petabyte = terabyte = gigabyte = megabyte = kilobyte =


byte
1000 terabytes 1000 gigabytes 1000 megabytes 1000 kilobytes 1000 bytes

divide by 1000 divide by 1000 divide by 1000 divide by 1000 divide by 1000

To convert from a larger unit to a smaller unit of storage:

petabyte = terabyte = gigabyte = megabyte = kilobyte =


byte
1000 terabytes 1000 gigabytes 1000 megabytes 1000 kilobytes 1000 bytes

multiply by 1000 multiply by 1000 multiply by 1000 multiply by 1000 multiply by 1000

138
369825_9.4_Cam_LSC_SB_129-159.indd Page 139 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

KEYWORDS
binary digit: 0 or 1; the smallest unit of binary data byte: eight bits of data, e.g. 01010011
represented on a digital device character: single letter, digit or symbol
bit: short for ‘binary digit’: 0 or 1 convert: change from one unit to another, e.g.
transistor: tiny switch activated by electrical storage units (e.g. bits/bytes/kilobytes)
signals – when the transistor is ON it represents 1; storage units: number of bits used to store a data
when the transistor is OFF it represents 0 item in a digital device
process: carrying out an operation on data, e.g. backup: copying files to another location in case
querying a database or doing a calculation using the original is lost or damaged
data in a spreadsheet

Computational thinking – decomposition and algorithms


A word-processed document contains 300 characters, including spaces. Using this
information, it is possible to work out how many bytes, kilobytes or megabytes are
needed to store the file, for example:
● If each character is stored using 8 bits, that means that
300 × 8 bytes are needed to store the word-processed
document. So, 300 3 8 = 2400 bytes. Remember: the
ASCII code that
● You can work how many kilobytes are needed to store the
represents the
file by dividing 2400 by 1000: 2400 4 100 = 2.4 kilobytes or
character set of
2.4 KB. most computers is
1 Another word-processed document is 6500 megabytes in 8 bits.
size. How many characters are there in the file?
2 A utility program stored on a computer hard drive is 30 megabytes in size. What is this
file size in bytes?

Practise
1 Create a rhyme or poem to help you remember the terms associated with units of
storage shown in the diagram above. Use your poem or rhyme to help you learn the
storage units from byte to petabyte in the correct order.
2 Explain to your partner how you can convert a file that is 2 PB
in size into GB.
Think about the
3 Explain to your partner how you can convert a file that is steps you followed
12,000,000 bits into MB. to convert between
4 Calculate in bytes the size of each of the following the storage units
programs. in the ‘Learn’ box.
a A 2-hour movie that is 7 GB. Make sure that you
stop dividing or
b A backup of the contents of the school server, which is
multiplying by 1000
3 petabytes. when you have
5 Convert the following files into the most appropriate arrived at a suitable
storage unit. storage unit.
a A word-processed document that contains 24,300 bytes
of data.
b A multimedia presentation that contains 2500 bytes of data.

139
369825_9.4_Cam_LSC_SB_129-159.indd Page 140 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Computer programming languages


Learn
The instructions to be carried out by a computer are provided by a computer program.
Program developers use high-level languages (HLL), such as Python or Scratch, to
write computer programs. These are programming languages that programmers easily
understand.
However, before the processor can carry out these instructions, they need to be
converted into a pattern of 1s and 0s (binary) that the Central Processing Unit (CPU)
understands. The CPU is the part of the computer that carries out program instructions.
The CPU is sometimes known simply as the processor. Every CPU has its own set of
binary instructions it understands. This is called its instruction set. The instruction set of
a CPU is written in binary (also known as machine code). Machine-code instructions are
instructions that the processor understands; they are written in binary format. Instructions
written in this format are known as low-level language (LLL) instructions.
When writing a program using
an HLL, the programmer does Remember: programs and data currently
not need to understand what is being used by a processor are stored in RAM while
happening inside the processor; the program is being run. When you are programming,
they only need to focus on writing a you give data items variable names. The variable names
program to solve a problem. are used to identify locations in memory where the
data items are being held.

The table below shows the difference between program instructions written in an HLL and
an LLL.

High-level language (HLL) Low-level language (LLL)


var1 = 0.5 10100101010010101010101
if var1 > 1.3 or var1 < 0.9:
● Easy for humans to read, write and modify ● More difficult for humans to read, write and modify
● Uses variables to identify locations in memory for ● Identifies locations in memory using actual location
storing data addresses when storing data
● Portable, which means it can be run by any CPU ● Not portable, which means it can only run on a CPU
with the same instruction set

Remember: computers only understand


instructions that are written in binary.

Each HLL instruction is often made up from more than one LLL instruction. Before a
programmer can write a program in an LLL, they need to understand what is happening
inside the processor. (You will explore this in detail in the next section.)
Low-level program instructions can be carried out by the processor easily as they
are already in a format the processor understands. However, they are not easy for a
programmer to understand. Programmers sometimes write instructions in a more easily
understood version of machine code, called an assembly language.

140
369825_9.4_Cam_LSC_SB_129-159.indd Page 141 06/03/23 12:58 PM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Each assembly-language instruction corresponds to one machine-code instruction in


the CPU’s instruction set. However, assembly language uses a set of codes or symbols
to represent each instruction, rather than a group of 1s and 0s. The assembly-language
instructions are therefore easier for human programmers to understand. The example
below shows how to output the word ‘Hi’ to a computer screen.

Assembly-language instruction Machine-code alternative


OUT "Hi" 10110101 01001000 01101001

Machine-code instruction ASCII for ‘H’ ASCII for ‘i’


for OUT (output)

The diagram below will help you to understand the link between the CPU hardware,
machine code, assembly language and high-level languages.

High-level languages, such as


Interpreters take
Python, JavaScript, Scratch
each line of a computer
program, translate it into
Assembly language
machine code and execute
that line of code before
Machine language moving on to the next line
of code. This often makes
the program slow to run and
CPU hardware may cause problems if the
code makes reference to a
Unless a computer program is written in machine-code variable that has not
format, it needs to be translated into machine code yet been used (declared)
before the processor can execute it. A translator carries in the program.
out this task. There are three different types of translator:
interpreters, assemblers and compilers.

Interpreter Assembler Compiler


● Translates each line of HLL code into ● Converts assembly- ● Translates the entire program into
machine code language machine code
● Carries out one instruction before instructions into ● Does not run the program until all lines
translating the next instruction, meaning machine code of code have been translated
that less main memory is needed to run ● Creates one ● Errors in the code are reported only at
the program as the instructions are not line of machine the end of the process; this can make
stored for use later code for each debugging difficult
● Errors are displayed as soon as they are assembly-language ● Takes a long time to compile the
encountered instruction program
● If an error is encountered, the program ● Does not convert ● Saves a copy of the translated code
execution stops; this is helpful when trying the entire program so it can be used over and over again,
to debug a program into machine code meaning compiled programs run
● Interprets the program each time it is run, in one go quickly
so is useful for applications designed to ● Useful for larger programs, e.g.
run on multiple platforms (e.g. web-based computer games, which may take a
applications written using Python) long time to compile

141
369825_9.4_Cam_LSC_SB_129-159.indd Page 142 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

KEYWORDS
high-level language (HLL): programming assembly language: set of codes or symbols that
language that uses commands and terms that are represent each instruction, rather than a group of
linked to the words or symbols a human would use 1s and 0s
when carrying out the same task translator: converts program instructions into
Central Processing Unit (CPU): the part of the machine-code format so the processor can carry
computer that carries out program instructions, out the instructions
sometimes known simply as the processor interpreter: translates each line of high-level
instruction set: all the instructions in machine code language code into machine code
that a Central Processing Unit can execute assembler: translates assembly-language
machine code: combination of 1s and 0s that instructions into machine code and creates one
represent each instruction in the instruction set of line of machine code for each assembly-language
a digital device instruction
low-level language (LLL): programming language compiler: translates an entire computer program
that uses commands that are similar to the type of into machine code and creates a file containing
instructions the processor understands machine code for the entire program
data item: piece of information that represents main memory: another name for RAM, which is
part of the data that makes up a person, place or used to store the programs and data the Central
thing, e.g. some of the data items that represent a Processing Unit is currently using
person are their first name and second name platform: hardware and operating system that runs
variable: named memory location that can store a an application
value

DID YOU KNOW?


Programs written in a low-level
programming language work only on
the computer system for which they
have been designed. LLLs are said to
be non-portable (that is, they cannot
be used on digital devices produced by
other manufacturers), unlike high-level
programming languages, which can
be installed and executed on different
computer platforms, for example,
Windows or iOS, which can be used to
interact with laptops, PCs, digital tablets
or mobile phones.

Practise
Create a mind map that explains why program translators are needed. Your mind map
should:
● show the key differences between high-level languages and low-level languages
● explain the different types of translators; make sure you list the characteristics of
compilers and interpreters.

142
369825_9.4_Cam_LSC_SB_129-159.indd Page 143 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

The fetch–decode–execute cycle

Learn
The main role of the Central Processing Unit (CPU) is to run (or execute) a set of stored
instructions known as a computer program. The CPU coordinates all the other parts of the
computer when it is executing a program.
A CPU has three main components, and it uses these components when it is carrying out
(executing) the instructions in a computer program.

Arithmetic logic unit (ALU) – carries out the calculations needed during the execution
of a program.

Control unit (CU) – issues commands to the other hardware components to ensure
that programs are carried out correctly.

Registers – store data about memory locations, instructions and data used during
execution of an instruction. The different registers are:
● Accumulator (ACC) – a register used by the ALU to store the results of the
processing the ALU carries out
● Program counter (PC) – stores the address of the next instruction waiting to be
executed (carried out) by the CPU
● Current instruction register (CIR) – stores the address of the instruction the CPU is
currently executing
● Memory address register (MAR) – holds the address of the memory location being
accessed, either to read data from or write data to
● Memory data register (MDR) – any data or instructions that pass into or out of main
memory must pass through the MDR.
Central processing unit Main memory

Arithmetic logic Registers Remember: all


unit (ALU) programs and
ACC data currently
PC being used by a
CIR digital device are
stored in RAM
MAR (sometimes known
Control unit
MDR as main memory).

143
369825_9.4_Cam_LSC_SB_129-159.indd Page 144 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Fetch–decode–execute
Computer programs stored in RAM are carried out by the CPU, one instruction at a time.
The CPU operates at an extremely high speed and, when it is executing a computer
program, it is able to carry out many instructions every second. It does this by going
through a set of steps known as the fetch-decode-execute cycle.
The fetch-decode-execute cycle has three stages:
1 Fetch – the CPU fetches an instruction from a Fetch
the next
location in memory. instruction

2 Decode – the CPU works out what the


instruction means, i.e. it is telling the CPU Execute Decode
what to do. the the
instruction instruction
3 Execute – once the CPU has figured out what
it has to do, it carries out that instruction.
The processor will continually fetch instructions
from memory, decode them and then execute (or
carry out) those instructions.

KEYWORDS
Central Processing Unit (CPU): the part of the current instruction register (CIR): stores the
computer that carries out program instructions, address of the instruction the Central Processing
sometimes known simply as the processor Unit is currently executing
arithmetic logic unit (ALU): carries out the memory address register (MAR): holds the
calculations needed during the execution of a address of the memory location being accessed,
program either to read data from or write data to
control unit (CU): issues commands to the other memory data register (MDR): any data or
hardware components to help ensure programs instructions that pass into or out of main memory
are carried out correctly must pass through the MDR
register: location in main memory that temporarily main memory: another name for RAM, which is
stores data about memory locations, instructions used to store the programs and data the Central
and data used during the execution of an Processing Unit is currently using
instruction fetch: collect an instruction from another location
accumulator (ACC): holds the results of processing decode: work out what an instruction means/what
carried out by the arithmetic logic unit it is telling the Central Processing Unit to do
program counter (PC): stores the address of the execute: carry out the instructions described in a
next instruction waiting to be executed (carried computer program
out) by the Central Processing Unit

Practise
1 Open the file CPU.docx provided by your teacher. Label each of the parts of the CPU
on the diagram. Include a description of the role each part plays in the fetch–decode–
execute cycle.
2 When you have completed the diagram, use the keywords in the diagram to explain how
computers store lists of instructions in main memory and how the processor uses the
fetch–decode–execute cycle to carry out those instructions one line of code at a time.

144
369825_9.4_Cam_LSC_SB_129-159.indd Page 145 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Running the program


Learn
In the ‘Learn’ box in the ‘Computer programming languages’ section, you learned
about the differences between high-level languages, assembly language and low-level
programming languages. You also learned that programs must be in machine-code
format before the processor can understand them. All programs and data stored in main
memory are stored in machine-code format. Each line of code in the high-level language
program may need more than one machine-code instruction to enable the processor to
carry it out. This is because the processor needs to use all the registers inside the CPU
correctly to help fetch and execute the instruction.
The simple high-level language instruction answer = num1 + num2 (in Python) is a lot more
complicated that you might first think. The machine-code version of the same instruction
needs to tell the processor which memory locations the data is stored in, where to load the
data to carry out the instruction and where to store the final result of the processing.
Below you can see how this single high-level language instruction requires the processor
to carry out three additional steps.

HLL instruction LLL instruction steps Remember: the


answer = num1 + num2 Load the contents of location 10 into accumulator is a special
the accumulator register that stores the results
Add the contents of location 11 to the of processing.
contents of the accumulator The three instructions for the
Store the contents of the accumulator processor to carry out are shown
in location 12 in English in the examples here,
but would be in machine-code
The machine-code instructions that the processor needs format (binary).
to carry out this simple Python instruction would be stored
in main memory, as shown below.

Main memory
Address Contents The main memory
0 Load the contents of location 10 into the accumulator locations 0, 1 and 2
would contain the machine-
Add the contents of location 11 to the contents of the
1 code instructions needed to
accumulator
carry out the Python instruction
2 Store the contents of the accumulator in location 12 answer = num1 + num2
3
Memory location 10 is used to
4 store the number stored using
5 variable ‘num1’; location 11 is
6
used to store the number stored
using variable ‘num2’; and
7 location 12 will be used to
8 store the answer variable
9 when the program
instruction is
10 (num1) 8
completed.
11 (num2) 2
12 (answer)

145
369825_9.4_Cam_LSC_SB_129-159.indd Page 146 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Three fetch–decode–execute cycles are now needed for the processor to carry out this
simple task.
● Cycle 1 will fetch, decode and execute the instruction stored in location 0.
● Cycle 2 will fetch, decode and execute the instruction stored in location 1.
● Cycle 3 will fetch, decode and execute the instruction stored in location 2.

KEYWORD
machine code: combination of 1s and 0s that represent each instruction in
the instruction set of a digital device

Practise
1 a Copy and complete the table below to convert the high-level programming
instruction into a description of the set of machine code instructions that the
processor would need to carry out to complete this line of code:
answer = num1 – num2 + num3

Main memory
Address Contents
0 Load the contents of location 12 into the accumulator
1
2
3
4
5
6
7
8
9
10
11
12 (num1) 8
13 (num2) 2
14 (num3) 7
15 (answer)

b Use your machine-code instruction example to show how the processor would need
four fetch–decode–execute cycles to complete this single line of code.
2 Discuss with your partner the steps a processor carries out when completing a
program instruction (the fetch–decode–execute cycle). In your discussion, describe the
registers the processor uses and the role each register plays during the fetch–decode–
execute cycle of the instruction shown in location (memory address 0).

146
369825_9.4_Cam_LSC_SB_129-159.indd Page 147 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Logic circuits
Learn
All processing inside a digital device is carried out using logic gates and logic circuits.
Most logic gates, for example the AND and OR gates, accept two inputs. The exception
to this rule is the NOT gate, which accepts just one input. Logic gates can be represented
using the following symbols:

Logic gates can be combined to represent conditional statements that have two or
more inputs to consider. Conditional statements use conditional operators. For example,
consider the scenarios in the table below and the algorithms used to describe the
processing required in each scenario.

Operator Meaning
= equal to
You met these > greater than
conditional operators < less than
in Stage 8.
>= greater than or equal to
<= less than or equal to
!= not equal to

A local gym uses the following conditional statement A computer program is helping a student to decide
to decide whether a new member is the correct age to whether the food type they have selected is a healthy
become a junior member of the gym. snack option.
IF age > 12 AND age < 16 then IF food = "apple" OR food = "orange" then
OUTPUT "This young person can become OUTPUT "The food you have selected
a junior member of this gym." is a healthy snack option."
END IF END IF
The conditional statement in this example could be The conditional statement in this example could be
described using the following Boolean expression: described using the following Boolean expression:
X = A AND B X = A OR B
where: where:
X = output statement X = output statement
A = condition 1 (age > 12) A = condition 1 (food = "apple")
B = condition 2 (age < 16) B = condition 2 (food = "orange")

Some problems require more than two inputs to be processed correctly. Consider the
following scenarios.

147
369825_9.4_Cam_LSC_SB_129-159.indd Page 148 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

A trip is being offered to students in school. A student A fun-run event is being organised in school and
can attend if they are Stage 9 OR if they are Stage 8 and students can get involved if they are Stage 8 or 9 AND
special permission has been given. they have brought in their permission forms.
IF (stage = 8 AND permission = TRUE) OR IF (stage = 8 OR stage = 9) AND
stage = 9 permission = TRUE
The conditional statements in this example could be The conditional statement in this example could be
described using the following Boolean expression: described using the following Boolean expression:
X = (A AND B) OR C X = (A OR B) AND C
where: where:
X = output statement X = output statement
A = condition 1 (stage = 8) A = condition 1 (stage = 8)
B = condition 2 (permission = TRUE) B = condition 2 (stage = 9)
C = condition 3 (stage = 9) C = condition 3 (permission = TRUE)

When a digital device needs to consider more than two conditional statements to solve a
problem, logic gates can be combined to create a logic circuit.
Boolean expressions, such as the examples above, can show how the logic circuit will
operate. The Boolean expressions can be used to draw a diagram showing how the logic
gates will combine to solve the problem.
For example, consider the logic circuit needed for the fun-run scenario above:
X = (A OR B) AND C
The following steps will help you to create a logic circuit from a Boolean expression.

1 Identify the label that represents the output from the circuit and show it at the right-
hand side of your diagram.
X

2 You must evaluate first any part of the expression shown inside brackets.
Add the correct logic-gate symbol for the conditional statement and label the inputs
on the left-hand side of your diagram.
A You need an OR to help you
P
with the first condition. You need
B X
to output True if the student is in
The output from this logic gate will be True if the Stage 8 OR Stage 9. You can label
student’s stage = 8 OR 9. the output from this logic gate with
another letter: in this example, P.
3 You can combine the True/False output from the
first logic gate with the third input value to consider.
Add a third input to your diagram to represent condition C: Permission = True.
A P
B X

4 Add an appropriate gate to show how this third conditional statement can be
combined with the output from your first logic gate to make the final decision.

148
369825_9.4_Cam_LSC_SB_129-159.indd Page 149 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Remember: a student can participate in the fun run if they are Stage 8 or Stage 9
AND they have permission to attend.
A P
Machine
B
learning and
X
computerisation
Remember to show how the output from the first
gate becomes an input to the second gate, along
C with the third input to the circuit.

KEYWORDS
conditional statement: completes a check to see Boolean expression: expression that contains
whether set criteria is either True or False conditional operators; symbols, e.g. >, < and =,
conditional operator: symbol, e.g. >, < and =, used used to carry out comparisons between two values
to carry out comparisons between two values logic circuit: combination of logic gates for solving
a problem in a digital device

Practise
1 Use the steps above to create a logic circuit for the Boolean expression below.

A trip is being offered to students in school. A student can attend if they are Stage 9
OR if they are Stage 8 and special permission has been given.

IF (stage = 8 AND permission = TRUE) OR stage = 9

2 Follow the steps below to write the Boolean expression for this problem.

A student is NOT able to participate in a school sports event if they are absent from
school OR late to the track.

In this case, there are only two inputs. X can be used to represent output from the circuit.

A = absent
B = late to the track

a Identify the correct conditional operator needed to complete the Boolean


expression for this problem.
X = NOT (A … B)
b Using the completed expression and the steps outlined in the ‘Learn’ box, draw a
logic circuit for this Boolean expression.
3 Draw logic circuits for the following Boolean expressions.
a X = NOT A AND (B OR C)
b X = (A OR B) OR NOT C

149
369825_9.4_Cam_LSC_SB_129-159.indd Page 150 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Machine learning and computerisation


Learn
Computer programs are needed to ensure that digital devices operate the way you expect
them to when you are using them. Many digital devices are able to make decisions or
perform tasks that they were not originally designed or programmed to do; this is made
possible through machine learning.

You have learned about machine learning in previous stages. Here’s a recap.

Machine learning is often confused with robotics and artificial intelligence (AI). Machine
learning is important in helping to develop AI devices: think, for example, about how mobile
phones start to understand your patterns of speech and can make recommendations for
keywords in text messages you send. While it is true that some robots use machine learning
to make sure that they work correctly in situations the programmer could not always
anticipate (for example, some robots in industrial settings use sensors and AI to allow them
to work safely in the busy environment around them), not all robots use machine learning.

Machine learning is found on many of the digital applications you use on a daily basis, for
example, internet search engines, email filters, online banking and biometric security systems.

Uses of machine learning


Speech
input and
language Think about
Product translation Self-driving digital devices that are
targeting cars able to recognise
authorised users and
Applications
Online allow them to sign in using
Route shopping
of machine and
facial recognition even
calculations
learning banking when their appearance
has changed: for example,
when wearing sunglasses,
Security Medicine with hair tied up or
Image when wearing a
recognition mask.

150
369825_9.4_Cam_LSC_SB_129-159.indd Page 151 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Potential uses of machine learning include:

Speech input Many digital assistants allow users to input instructions by speaking in normal sentences.
and language By combining machine learning with AI, the devices are able to follow voice commands and
translation complete tasks correctly. Communicating with other people using unfamiliar languages has
been made easier using apps that automatically translate spoken, written or scanned text
from one language into another.
Self-driving cars Self-driving cars use data collected from sensors and online sources to make decisions.
They use this data to select the most efficient route to take to a destination and to avoid
obstacles on the journey.
Online shopping Online shopping and banking have provided criminals with opportunities to commit crimes
and banking through the creation of fake websites to steal login and bank details. Machine learning
ensures that unusual online activity is quickly detected so that customers can be alerted, and
unauthorised activities can be stopped quickly.
Medicine Machine learning is often used by manufacturers of medicines to predict how an illness will
respond to new medications. When diagnosing illnesses, machine learning can analyse large
amounts of patient data, including images of scans, to make an accurate diagnosis and
create personalised health plans for patients.
Image recognition Used with many digital devices to allow authorised users access to the device, some software
uses facial recognition to allow users to categorise photographs according to content or
faces.
Security Machine learning analyses emails and internet use and can alert authorities quickly to
potential threats.
Route calculations Satellite-navigation systems in cars use data from a range of sources, e.g. sensors in the car
and real-time traffic data. This is used to choose the fastest or most economical route for a
journey.
Product targeting Many online stores and services collect data about users, including websites viewed, TV
shows watched and online shopping purchases made in the past. This data can be used to
make recommendations for future purchases.

Computerisation
The range of applications for machine learning and computing technology is far reaching.
Many traditional manufacturing and industrial practices have also been computerised.

151
369825_9.4_Cam_LSC_SB_129-159.indd Page 152 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Here are some examples.


● The manufacturing industry was traditionally an industry that employed skilled crafts
people to create new products. As technology advanced, robots that were designed
to complete a single task with no input from the environment replaced human workers.
When a product design changed, the robots needed to be reprogrammed to allow
them to create the new design. Today, computer-aided manufacturing of new products,
using computing technology to monitor and control the manufacturing process, means
that products are produced to a high and consistent standard.
● Monitoring of stock levels, using special technology known as radio frequency
identification (RFID) tags. Manufacturers are able to track the location and levels of
stock and parts needed to produce products they are making. This technology is even
used in checkout-free stores, where digital systems in the store track the products a
customer has selected and automatically charge for them when the customer leaves
the store. Previously, staff would have completed this task manually, along with
counting stock levels on shop floors and warehouses. This allowed stores to decide
when new products needed to be reordered, but this task is now often automated.
● Managing communications between clients and businesses. Computing technology
is used in chatbots to troubleshoot problems. Before the introduction of chatbots,
businesses would employ staff members to answer telephone calls and respond to
customer queries.
● Targeted advertising. By collecting data about users via small programs called
cookies, AI applications can send targeted advertisements to potential customers.
Previously, adverts were posted publicly, for example, using large boards on roadsides,
on television or on radio, in the hope that potential customers would see them.
Here are some of the benefits and risks of computerisation.
Benefits Risks
● The products produced are a better and more ● Technology can be expensive to purchase
consistent quality ● Costs are unknown – computers need to be repaired
● Computers can work 24/7 if they break down
● There is less chance of injury at work as fewer ● Some staff may lose their jobs
humans are involved in the workplace

Industry 4.0
As so much manufacturing today requires the use of computers and digital technology, it
is often referred to as the fourth industrial revolution or Industry 4.0.
The table below shows of the pros and cons of Industry 4.0.
Pros Cons
● Improved security and access to data for analysis can ● Many people are still concerned about the security
lead to better surveillance and traffic monitoring and of personal data that is needed to support online
help businesses save money on the transportation of activity
goods ● High reliance on technology leads to problems if the
● Improved communications can reduce travel needs, technology fails
make it easier to conduct business and shop online, ● Many of the staff normally employed in industry and
allowing products to reach a wider market manufacturing may no longer be needed, leading to
● New technologies, e.g. drones, can monitor job losses
traffic and help businesses save money on the ● Staff need to be retrained; this can be stressful for
transportation of goods some who are not confident in the use of technology

152
369825_9.4_Cam_LSC_SB_129-159.indd Page 153 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Pros Cons
● Increased telecommunications links mean that all ● Many worry about the lack of social and personal
areas are connected digitally, improving social links in interactions, which is important to staff
remote areas; this can help products to be advertised ● Technology is expensive and a lot of investment is
and available to a wider market needed
● Production lines are now more efficient and this can
help organisations to increase their productivity
● Production can easily be amended to respond to
customer need
● Predictive maintenance means problems with
technology are anticipated and responded to quickly
and this helps to limit equipment downtime
● High- and consistent-quality goods are now available
to customers

KEYWORDS
machine learning: ability of a computer system to chatbot: software application that uses text to ask
learn over time questions to help a user
artificial intelligence (AI): ability of a computer industrial revolution: rapid change in how
system to learn and develop its own programming society works following the introduction of new
from the experiences it encounters developments, e.g. machines, computers, robots,
traditional manufacturing: the making of products AI, machine learning
before computerisation; it often relied on human Industry 4.0: refers to how industry is combining
production lines, where people completed electronics with new technologies, e.g. machine
individual tasks, which were passed along the learning, artificial intelligence, robotics and green
production line until the final product was complete energy
radio frequency identification (RFID) tags: cookies: small pieces of data, collected from
technology that uses radio signals to send data to websites and stored as text by web browsers
another device

Practise
1 Write a short paragraph explaining what is meant by the term machine learning.
2 a Use the ‘Learn’ box to describe to your partner three examples where machine
learning is used in today’s society.
b Use the internet to carry out research and find three additional applications or
scenarios where machine learning may be useful to society.
3 Copy and complete the table below to show how machine learning has affected the
scenarios you examined in task 2.
Industry Task How the task How the task is Benefits of Cons of
was completed completed now computerising computerising
previously
Car Assembling Previously Robots now use Design software Fewer staff are
manufacturing parts to carried out using sensors to ensure that can easily be needed so some
make car robots designed movements are precise altered to create jobs are lost
bodies for only one task Robots are also linked custom cars The software and
to computer-aided Cars produced technology needed
design software are high quality is expensive

153
369825_9.4_Cam_LSC_SB_129-159.indd Page 154 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Improving technology
Learn
The way you do tasks on a day-to-day basis and the way in which tasks are completed
in industry continually change as new devices and programs are developed and
improvements are made to the technologies we use. Consider how mobile phone
technology has changed over time.

As users’ needs change, designers must consider how their digital devices operate, what
they look like and how user friendly they are. When a new technology is being developed,
it is common for the designers to build a prototype of the new product. Prototypes can
be created in a variety of formats: for example, they can be a paper-based design, a
computer-aided design representation, a physical model or a 3D model of the product.

Product designers and even software developers often use the prototype to help
them test the product, and also use it to help make decisions about how they can
improve the product before finalising the design. Sometimes, the developer may allow
potential customers to use the prototype so they can get some feedback on possible
improvements that may be needed.
As designs are reviewed, here are some of the areas that designers might consider.

● User experience: This refers to whether a user is able to use the product easily and
confidently, no matter how familiar they are with technology. For example, if the
product is for young children it should be intuitive.
● Accessibility: This refers to how successfully a new product or piece of software can
be used by anyone. Things to consider include any physical limitations the expected
user might have.
● Ergonomics: This is how a product or piece of software is designed or arranged so the
user can use it efficiently. Examples include computer screens with swivel bases so that
users can adjust the viewing angle, and computer-control devices such as mice and
joysticks that are designed to fit into a user’s hand so that they are comfortable to use.
● Emerging technologies: New technologies can be incorporated into a design to
improve how the product operates.

154
369825_9.4_Cam_LSC_SB_129-159.indd Page 155 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

KEYWORDS
prototype: initial product created for testing and accessibility: how successfully a new product or
reviewing, before a final product is released piece of software can be used by anyone
feedback: comments made to help improve a ergonomics: how a product or piece of software
product is designed or arranged so that it can be used
user experience: how intuitive the product is efficiently
based on the user’s previous experience with emerging technologies: new technologies that can
digital products or applications be incorporated into a design to improve how the
product operates

Practise
1 With your partner, identify an item of technology that you have access to at home or
in school.
a Discuss the device as though it were a prototype design. Identify what you could do
to improve the ‘prototype’ to make the technology easier for another person to use.
b Make a list describing how you can make the device more:
– user friendly
– accessible
– ergonomic.
c Are there any emerging technologies that you would like to include in your design?
2 Present your prototype to a small group of four. In your presentation:
– identify improvements you made to the design based on increasing the product’s
user-friendliness, accessibility and ergonomic appeal to other users
– explain why factors such as user experience, accessibility, ergonomics and
emerging technologies are important.

Go further
Converting between storage units is an important part of
managing memory in digital devices. Remember: use multiply and
Use what you learned in the ‘Data storage’ section to divide by 1000 to convert
work out the minimum amount of storage between data-storage units.
needed to store each of the files below.

● A black and white image


● The image is made up of 2000 pixels × 2000 pixels
● Each pixel is represented by 1 bit

● A black, white and grey image


● The image is 20,000 pixels × 2000 pixels
● Each pixel is represented by 3 bits

155
369825_9.4_Cam_LSC_SB_129-159.indd Page 156 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

● An MP3 sound file


● The sound file contains a song that is 3 minutes long
● 1 megabyte is needed to store 1 minute

● A word-processed document
● The text in the file is represented using 8-bit ASCII
● The text file contains 2500 characters

● An email containing a short message


● The email needs 1 kilobyte of memory
● The user adds the black and white image from the top of this table
● The user then adds the text file from this table

Challenge yourself
Some complex logic circuits are created when processors A P
carry out complex tasks. Creating Boolean expressions B
from logic circuits is an important part of understanding Z
processing in the CPU.
1 Copy and complete the Boolean expression below to explain C
Q
how the logic circuit shown on the right operates.
Z=( ) AND
2 Truth tables are used to describe the operation of logic gates.
a Do some research about truth tables using the internet.
b Copy the truth table below. Complete it to describe the operation of the complex
logic circuit shown in question 1.

A B C P = A OR B Q = NOT C Z = P AND Q
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

KEYWORD
truth table: breakdown of a logic circuit, listing all possible operations the
logic circuit can carry out

156
369825_9.4_Cam_LSC_SB_129-159.indd Page 157 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

Final project
Look back at the start of this unit to remind yourself of the Scenario. You now have
all the skills and knowledge you need to create the resources that the computing
technology company needs to deliver the workshops.
Compete the tasks below.
Part 1: Presentation
Create a presentation that explains the following.
● Slides 1–2:
Different types of systems software, including the role played by the operating system
and utility programs such as device drivers, security software and disc defragmentation.
● Slides 3–4:
The difference between high-level languages and low-level languages and the need
for language translation.
– Include a description of why different types of translators are needed.
– Describe the key features of a compiler and an interpreter; provide examples of
when each might be used.
● Slides 5–6:
What is meant by the fetch–decode–execute cycle and how it carries out instructions
stored in memory one after another.
– Include the registers used in the fetch–decode–execute cycle and the role they play.
● Slides 7–8:
What is meant by machine learning.
– Research and include examples of applications that use machine learning.
– Include a short description of how at least three manufacturing or industrial
practices use machine learning today.
● Slides 9–10:
The advantages and disadvantages of computerisation.
– Include examples of traditional manufacturing and industry areas that
computerisation has affected.
Part 2: Poster
Create a poster that helps other students understand units of storage, from a single bit
up to and including a petabyte. Include examples of files or applications where each
unit can describe a file or a data item: for example, a bit is used to store a single binary
digit (0 or 1).
Part 3: Worksheets
1 a C reate a worksheet containing five questions that another student can complete
to practise converting data between units of storage.
b Create an answer sheet that allows a class teacher to mark the other student’s work.
2 Create an information worksheet that includes a diagram explaining to another
student how analogue sound is converted to binary format.
– Include in your worksheet the terms ADC, sampling, sample rate and bit depth.
– Include advice on how to increase the quality of a sound sample.

157
369825_9.4_Cam_LSC_SB_129-159.indd Page 158 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

3 a Create a worksheet that asks students to convert the following Boolean


expressions into logic circuits, with an explanation about how to do this.
– X = NOT A AND (B OR C)
– X = (A OR B) AND NOT C
– X = NOT A OR NOT B
– X = NOT A AND NOT B
b Create an answer sheet for the logic-circuit questions in part a.
Part 4: Prototype design
Produce a prototype design for a new piece of technology that allows you to complete
a daily task more easily.
● Your design can be a diagram or a written description, but it should make use of a
new or developing technology.
● Include ideas about how you could make your new design user friendly and accessible.
Also include how you could make it more ergonomic and use emerging technologies.

Evaluation
1 Swap presentations with your partner and comment on the following:
– Is your partner’s definition of systems software accurate? Does it include the role
played by the operating system and utility programs such as device drivers, security
software and disc defragmentation?
– Is it clear from your partner’s presentation why language translation is needed?
Have they clearly described the key features of a compiler and an interpreter?
– Has your partner clearly explained the fetch–decode–execute cycle and how it is
used to carry out instructions stored in memory one after another?
– Has your partner clearly explained what is meant by machine learning?
Have they included appropriate examples of how machine learning is used in
manufacturing or industrial practices today?
– Has your partner identified the advantages and disadvantages of computerisation
and included examples of traditional manufacturing and industry areas that
computerisation has affected?
2 Swap posters and discuss the following:
– How clearly does your partner’s poster describe the units of storage from bit to
petabyte?
– How appropriate are your partner’s examples of files or applications for each unit?
3 Ask your partner to complete your worksheets. Use your answer sheet to mark their
work. Comment on any answers you disagreed with and discuss the differences. Make
corrections as necessary.
4 Swap prototype designs. Comment on the following in your partner’s design:
– How user friendly it is
– How accessible it is
– How ergonomic it is.
Suggest how your partner could improve their design.
Improve your design based on your partner’s comments.

158
369825_9.4_Cam_LSC_SB_129-159.indd Page 159 06/03/23 9:52 AM A4902 /142/HO02737/work/indd

Unit 9.4 Drilling down: How the processor handles instructions

What can you do?

Read and review what you can do.


✔ I can identify improvements to the design of digital devices
based on prototypes.
✔ I can explain why factors such as user experience,
accessibility, ergonomics and emerging technologies are
important to the design of digital devices.
✔ I can explain which tasks an operating system carries out.
✔ I can describe examples of utility programs, including
drivers, security software and defragmentation.
✔ I can explain the different types of translator.
✔ I can describe the main characteristics of compilers and
interpreters.
✔ I can explain how analogue sound is digitised.
✔ I can explain how to convert between storage units.
✔ I can draw logic circuits for Boolean expressions.
✔ I can explain how computers store lists of instructions to be
run one at a time.
✔ I can explain the fetch–decode–execute cycle.
✔ I can describe what is meant by machine learning and
identify a range of applications and scenarios that use
machine learning.
✔ I can explain the benefits and risks of computerising tasks in
industry and manufacturing.

159
369825_9.5_Cam_LSC_SB_160-197.indd Page 160 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Big Data modelling and


Unit analysis: Databases
9.5 and spreadsheets

Get started!
Many organisations need huge amounts of data to
operate successfully. For example, shops that sell
clothing or music online store details about their
customers, such as usernames and passwords,
delivery addresses and payment details. They collect
the data they use from many different sources, and it
can be in many different formats.
Social-media applications provide users with data in
the form of video, animated graphics, text and images.
They also collect data about users, and this can be
in many different formats. Like other organisations,
social-media companies analyse the data they collect
to learn more about their users. Many social-media
applications collect, for example, data about users’
physical location, other social-media pages they have
visited or even other internet pages they have visited.
Doing this allows the social-media platform to display
advertisements or suggest other pages and content
that might be of interest to the user.
Discuss with your partner:
l What type of data do you think organisations such as social-media providers collect
when they are trying to learn more about their users?
l What do you think they use this data for?
l How do you think the organisation is able to analyse this data?

In this unit, you will learn more about the concept of ‘Big Data’. You will examine the
key features of Big Data and how Big Data is valuable to organisations in a range of
application areas. You will also explore a range of scenarios and examples to help you
to learn more about a variety of the functions in applications such as MS Access and MS
Excel for modelling real-life scenarios. By exploring how a school managing a new online
learning application can use both applications, you will learn how to use the MIN, MAX, IF
and COUNT functions in MS Excel, in addition to learning new skills to develop and use a
complex MS Access database containing more than one table of data.

KEYWORD
social-media application: web-based software that allows users to share
ideas, information and thoughts in an online community

160
369825_9.5_Cam_LSC_SB_160-197.indd Page 161 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Learning outcomes
In this unit, you will learn to:
l evaluate the use of models that represent real-life systems
l use functions in spreadsheets to analyse data, such as IF, MIN, MAX, COUNT
l create spreadsheets that model real-life systems
l evaluate the suitability of a spreadsheet for given purposes
l create relational databases with two or more linked tables
l create complex searches for data in databases using two or more criteria
l create complex searches in relational databases
l explain the term Big Data and describe its applications.

Warm up
In the last week, it is highly likely that
you, or family members, have provided
an organisation with some data. It is also
highly likely that an organisation you
interact with has accessed and used data
it has recorded about you.
With your partner, think about
organisations that hold data about you or
your family members.
1 Make a list of the data items you think
each organisation stores about you.
2 What do you think they will use that
data for?
3 What software do you think they might use to help them to analyse that data?

SCENARIO KEYWORDS
You school is introducing a new online learning tool, a virtual learning data: raw facts and
figures
environment (VLE), which teachers will use to make learning resources
data item: piece of
available to students. Teachers will post handouts, homework and information that
assessments on the VLE, sorted by subject page. Students will use an represents part of
app to access the subject pages on the VLE. the data that makes
up a person, place or
The school has collected a lot of data about the potential users of the thing, e.g. some of
VLE, the pages each subject department is creating on the VLE, the the data items that
times and who is accessing each VLE page, and why the pages are represent a person
being accessed: for example, is a teacher accessing the page to update are their first name
and second name
content, or is a student viewing a page to read content?
virtual learning
The school have heard of the term Big Data and wonder whether environment (VLE):
the amount of data they need to enable them to model student and online classroom
where teachers and
teacher use of their new VLE can be categorised as Big Data. They students can share
have asked you to help them to understand what this term means. learning materials

161
369825_9.5_Cam_LSC_SB_160-197.indd Page 162 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The school has asked you to create a relational-database application KEYWORDS


that they could use to model student and teacher VLE access. relational database:
database that stores
They’ve also asked you to create a spreadsheet model that they can data using two or
use to analyse student and teacher use of the VLE pages using various more linked tables
platforms, such as a PC, mobile phone or tablet device. spreadsheet
model: spreadsheet
containing data that
represents a real-life
The things that the school would like to use these applications scenario
to keep track of include: platform: hardware
l user login details that show how often students access and operating
system that runs an
pages on the VLE application
l the time of day users access the VLE
l on average how long students or teachers view pages on
the VLE
l how many users access the VLE using platforms such as DID YOU KNOW?
PCs, laptops, tablets or mobile phones
l the total number of times teachers or students access
specific VLE pages
l how many times certain VLE pages are accessed
l how often different types of users access various types of
resource pages: for example, how often teachers access a
markbook page or how often students access a multimedia VLEs can be used
to support distance
tutorial page
learning and also
l time spent on specific VLE pages by all users. provide students with
an opportunity to
review content delivered
in the classroom at a
Do you remember? pace that suits their
own learning.
Before starting this unit, you should be able to:
✔ amend the design of a database table using MS Access
✔ decide on an appropriate primary key field and other field
headings for a table in an MS Access database
✔ select data types for fields in a database model
✔ identify the data needed to model a real-life situation
✔ search a database using a single search criterion
✔ evaluate the suitability of a database or a spreadsheet model
for a given scenario
✔ create spreadsheet models that use predefined functions such
as SUM and AVERAGE.

Before starting this unit, you will need to install the following
software on your own personal device (or use a similar database
and spreadsheet software application):
l MS Access l MS Excel

162
369825_9.5_Cam_LSC_SB_160-197.indd Page 163 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Introducing ‘Big Data’


Learn
In ‘Get started!’ at the start of this unit, you considered the many different types of data
made available to organisations today. Data used by organisations can be in the form of
images, video, audio, animation, text or even Global Positioning System (GPS) data. The
data can be presented in the form of ‘like’ or ‘dislike’ icons on a social-media website, live
video streams or location data. Large organisations are able to use all of this data to learn
more about their users and potential customers, and help them to promote their goods
and services. However, for the data to be useful to the organisations, they must be able to
access and analyse the data at an extremely high speed.
In the past, organisations used applications such as databases and spreadsheets to help
them to make sense of data they had collected. With data now being generated in so many
different formats and at such high speeds, traditional applications such as databases and
spreadsheets are not always able to process and at such high speeds the data.
Data that cannot easily be processed using traditional applications is known as Big Data.
Big Data can be described using 5Vs.

Big Data
Volume Value Veracity Variety Velocity

l Volume: Companies collect and analyse massive amounts of data on an ongoing


basis. If the volume of data is large enough, it can be considered to be Big Data.
l Value: This refers to how useful the data is. What can the organisation do with the data
they have collected? Are they able to get useful information from the data quickly?
l Veracity: This refers to accuracy and quality of the data. In Big Data analysis, the
applications analysing the data determine how reliable or accurate the data is. The
data-analysis software tries to determine whether the data is from a reliable source
or whether the data is the most up-to-date version.
l Variety: Data can be presented in a range of data formats and data types. Data
collected and stored in databases or spreadsheets tends to be structured: for
example, it may be organised under field headings. The data collected and used in
Big Data applications is not easily organised in this way.
l Velocity: Data being collected may come from many different sources, such as other
computers, smart devices or even social media. Velocity refers to how quickly the
data is generated, processed and turned into useful information.

163
369825_9.5_Cam_LSC_SB_160-197.indd Page 164 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The analysis of Big Data sets is known as Big Data analytics. The analysis of Big Data sets
can help organisations to use the data they have collected more efficiently and to identify
new opportunities.
The following table gives some of the applications of Big Data.

Application Example of Big Data use


Transportation Google Maps uses Big Data analytics to plan routes that are efficient, helping drivers
avoid routes affected by traffic and improving fuel consumption.
Delivery companies UPS analyses vehicle telematics from cars and trucks along with advanced
algorithms to calculate the best routes, automatically control engine idle time and
predict when maintenance is needed.
Mobile-phone companies Some mobile-phone companies combine data from a number of their customer-
management, billing and social-media applications to predict when a customer
might want to leave the organisation and go to another mobile-phone company.
Medicine/healthcare Search engines such as Google work closely with health providers to track when
users are inputting search terms related to, for example, flu topics. Working
together, the organisations can predict which regions may experience outbreaks.
Big Data analysis can also help medical professionals to predict and prevent
some diseases.
Media streaming services Media streaming services such as Netflix analyse international viewing habits before
they create or buy programmes that will appeal to their audience.
Advertising and marketing Advertising companies often buy or gather huge quantities of data to identify what
consumers actually click on, search for and ‘like’ when they are online. This data is
used to tailor advertising campaigns more effectively.
Banking Banks make use of Big Data analytics in the speedy identification of unusual
account activity. This allows them quickly to flag potential illegal use of their
customers’ bank details.
Meteorology Using data collected worldwide by satellites and other sensors, Big Data analysis
allows meteorologists to produce accurate weather forecasts, predict natural
weather-related disasters and make predictions about the impact of issues such as
global warming.

KEYWORDS
data type: classification applied to a data item process: carrying out an operation on data, e.g.
specifying which type of data that item represents, querying a database or doing a calculation using
e.g. in a spreadsheet some of the data types data in a spreadsheet
available include currency, text and number Big Data: datasets that are too large or complex
Global Positioning System (GPS): satellite-based for traditional data-processing applications, e.g.
system that keeps track of users’ physical locations databases or spreadsheets, to process
and helps with navigation 5Vs: the terms used to describe the concept of Big
database: application that organises data for Data: volume, velocity, variety, value, veracity
storing, processing and accessing electronically volume: the massive amounts of data collected
spreadsheet: application that uses rows and analysed on an ongoing basis
and columns to organise data and carry out velocity: how quickly data is generated, processed
calculations using that data and turned into useful information

164
369825_9.5_Cam_LSC_SB_160-197.indd Page 165 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

KEYWORDS
variety: the range of data formats and data types vehicle telematics: information monitored and
collected transmitted from vehicles, e.g. their location and
value: how useful data is to an organisation speed, using GPS, engine diagnostics and driving
style
veracity: accuracy and quality of data
algorithm: step-by-step instructions to solve a
Big Data analytics: the analysis of sets of data
particular problem
known as Big Data
meteorology: study of climate and the weather

Practise
1 Search the internet for more information on how Big Data is used. Write a paragraph
to explain the term Big Data and describe its applications.
2 Select one of the applications of Big Data in the table in the ‘Learn’ box. Copy and
complete the table below to include a list of pros and cons of using Big Data analytics
in the application area you have selected.

Pros of Big Data in [add your application here] Cons of Big Data in [add your application here]

3 With your partner, describe an example of an organisation you are familiar with
that uses Big Data. Tell your partner how the organisation uses Big Data and the
advantages to that organisation of using Big Data.

Introducing relational databases


Learn
Organisations use databases to help them to manage large quantities of data. The
simplest databases look more like large tables of information organised under a set
of headings.
The data on the next page is taken from a database that has only one table of information;
this is known as a flat-file database.
You can see in this database extract that the continent of Asia is referenced a number
of times.
For example, the table, country_continentTBL, shows an extract from a database that
records the details of some countries around the world. Some of the data in the table
appears multiple times: for example, the data related to the continent of Asia. This data is
repeated unnecessarily. Having data that is repeated unnecessarily can sometimes lead to
the introduction of errors in the data.

165
369825_9.5_Cam_LSC_SB_160-197.indd Page 166 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

country_continentTBL Unnecessary repetition of data.

Country Size of continent Continent


Country name Capital city population Continent (square miles) population
India New Delhi 1,420,062,022 Asia 17,139,445 4,436,224,000
Brazil Brasilia 209,737,513 South America 6,880,706 442,535,000
Nigeria Abuja 200,962,417 Africa 11,677,239 1,216,130,000
Philippines Manila 108,106,310 Asia 17,139,445 4,436,224,000
Vietnam Hanoi 97,429,061 Asia 17,139,445 4,436,224,000
Germany Berlin 82,438,639 Europe 3,997,929 738,849,000
France Paris 67,480,710 Europe 3,997,929 738,849,000
UK London 66,959,016 Europe 3,997,929 738,849,000
Canada Ottawa 37,279,636 North America 9,361,791 579,024,000
Saudi Arabia Riyadh 34,140,662 Asia 17,139,445 4,436,224,000
Peru Lima 32,933,835 South America 6,880,706 442,535,000
Australia Canberra 25,088,636 Australasia 2,697,909 34,601,860
Taiwan Taipei 23,758,247 Asia 17,139,445 4,436,224,0

Compare the population of Asia in the last row of this


database with the other references to Asia. An error
has been made when the value was entered for the Look carefully at the value for
final record in this database table. the Continent population of
Asia in the last row of this flat-
When the same piece of data is held in two separate file database example. Can you
places in a database, it is known as data redundancy. detect an error in the data?
Data redundancy can increase the chance of data-
entry errors occurring when a new record is added.
Relational databases can help to prevent this type
of error occurring by removing data redundancy. Look carefully at the flat-file
Relational databases use additional tables to store database example above. Can you
the data relating to each entity in the database. An identify other places where data is
entity is an individual person, place or object. In this repeated unnecessarily?
example, there are two entities: country and continent.
Therefore, you should create two tables, and use
one of the tables to record the repeating data items.
The headings used to organise data in a relational- This means that the data relating
database table are known as attributes: for example, to the fields ‘Continent’, ‘Size
continentTBL on the next page has three attributes. of continent’ and ‘Continent
population’ need only be entered
A single entry is made in this table for each data item once into the database.
being recorded.

166
369825_9.5_Cam_LSC_SB_160-197.indd Page 167 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

continentTBL

Continent Size of continent (square miles) Continent population


Asia 17,139,445 4,436,224,000
Africa 11,677,239 1,216,130,000
Australasia 2,697,909 34,601,860
Europe 3,997,929 738,849,000
North America 9,361,791 579,024,000
South America 6,880,706 442,535,000

The database now consists of two tables, as shown below: countryTBL and continentTBL.
countryTBL can use continentTBL to look up additional details for each country.
countryTBL continentTBL

Size of
Country Country continent Continent
name Capital city population Continent Continent (square miles) population
India New Delhi 1,420,062,022 Asia Asia 17,139,445 4,436,224,000
Brazil Brasilia 209,737,513 South Africa 11,677,239 1,216,130,000
America
Nigeria Abuja 200,962,417 Africa Australasia 2,697,909 34,601,860
Philippines Manila 108,106,310 Asia Europe 3,997,929 738,849,000
Vietnam Hanoi 97,429,061 Asia North America 9,361,791 579,024,000
Germany Berlin 82,438,639 Europe South America 6,880,706 442,535,000
France Paris 67,480,710 Europe
UK London 66,959,016 Europe
Canada Ottawa 37,279,636 North
America
Saudi Arabia Riyadh 34,140,662 Asia Notice that the attribute
Peru Lima 32,933,835 South ‘Continent’ appears in both tables.
America The ‘Continent’ field provides
a link between countryTBL and
Australia Canberra 25,088,636 Australasia
continentTBL.
Taiwan Taipei 23,758,247 Asia
When a continent name appears
in countryTBL, the database will
In this example, ‘Continent’ is the primary access continentTBL to look up the
key for continentTBL but it also appears in remaining information.
countryTBL to create a link between the two ‘Country name’ is unique for each
tables. When the primary key from one table record in countryTBL so it can be used
appears in another table to create a link, it is as the primary key in countryTBL.
known as a foreign key. ‘Continent’ is a foreign ‘Continent’ can
key in countryTBL. be used as the primary key in
continentTBL.

167
369825_9.5_Cam_LSC_SB_160-197.indd Page 168 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

KEYWORDS
table: set of facts or figures that are set out in a column and row structure
flat-file database: database that stores all data items using one table
data redundancy: when data is unnecessarily repeated in a database
data-entry error: error that occurs when data is being entered into a
database
relational database: database that stores data using two or more linked tables
entity: person, place or object represented in a table in a relational database
attribute: heading for organising data in a relational database
primary key: field in a database table that provides a unique identifier for a
record/entity
foreign key: when the primary key from one table appears in another table
to establish a link between two entities

Practise
1 The flat-file database below stores data about students’ scores in examinations they
have taken at school this year.

StudentID Name Class Exam ExamScore ExamGrade


1001 A Student 9X2 Mathematics 89 B
1002 M Student 9X3 Mathematics 92 A
1003 P Student 9Y7 Mathematics 77 C
1001 A Student 9X4 Art 90 A
1002 M Student 9X3 Art 84 B
1003 P Student 9Y10 Art 87 B
1001 A Student 9X2 Science 71 C
1002 N Student 9X3 Science 75 C
1003 P Student 9Y7 Science 88 B

a Identify the data items that have been


unnecessarily repeated in this flat-file database.
The fields that are unnecessarily
b Identify two examples where unnecessary repeated may not always be the
repetition of data has led to data-entry errors last fields in the table.
in this table.
c List two attributes that appear in this flat-file database table.
d Name two entities represented in this flat-file database table.
2 a Copy and complete the following to show how you could split this flat-file database
into two tables to create a relational database and remove data redundancy.

Add your table name here Add your table name here

List the table attributes here List the table attributes here

168
369825_9.5_Cam_LSC_SB_160-197.indd Page 169 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

b Place an * beside the primary key field in each of your tables.


c Circle the field that will be used to link the two tables together.
3 Relational databases can sometimes contain more than two entities. This means that
the database needs more than two data tables. The flat-file table below keeps track of
students’ book loans from the school library. Identify the three entities represented in
this table.

Student Student Class LoanID DateOut DateBack BookID BookTitle BookAuthor


ID Name
1001 A Student 9X2 L1 21 Jan 30 Jan B9865 Learn P Author
Programming
1002 M Student 9X3 L2 22 Jan 31 Jan B8856 AI Today Q Writer
1003 P Student 9Y7 L3 22 Jan 31 Jan B7787 Python L Expert
Programs
1001 A Student 9X2 L4 1 Feb 10 Feb B5654 Relational P Creator
Databases
1002 M Student 9X3 L5 3 Feb 13 Feb B7231 Spreadsheet J Modeller
Modelling
1001 A Student 9X2 L6 12 Feb 22 Feb B5541 Database S Story
Queries
1001 A Student 9X2 L7 12 Feb 22 Feb B6632 Big Data B Article

4 Copy and complete the following to show the attributes needed for each table to
convert this flat-file database into a relational-database model.
Remember to * the primary keys in each table.

studentTBL loanTBL bookTBL


List the table List the table List the table
attributes here attributes here attributes here

Remember to include foreign keys to


help you link this table to the others.
Circle the foreign keys in this table.

169
369825_9.5_Cam_LSC_SB_160-197.indd Page 170 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Creating relational databases


KEYWORDS
Learn
primary key: field
in a database table
In the previous section, you learned that a common field is that provides a
needed to link together tables in a relational database. Remember unique identifier for a
how the ‘Continent’ field was used to link continentTBL and record/entity
countryTBL. Remember: this common field will be a primary key relationship:
in one table, which is added to another table as a foreign key. feature in database
applications for
However, just adding the fields to the tables is not enough. The linking tables
tables in a relational database must also be linked using a special together
feature known as a relationship. entity: person, place
or object represented
Each table in a relational-database model represents different
in a table in a
entities that exist in the database model, for example in the school- relational database
library example from the last ‘Practise’ box, the data model you one-to-one
developed on paper had three entities: students, loans and books. relationship: a
primary key can exist
The entities in a relational database can be linked in a number
once as a primary
of different ways. In the library database example, each student key on one table in a
was represented only once in studentTBL, so their StudentID relational database
appeared only one time in studentTBL. A student’s studentID and once as a foreign
could then appear in the loanTBL as a foreign key as it links the key to link a second
table in the relational
two tables together. It would be reasonable to assume that a
database
student could borrow more than one book, so their studentID
one-to-many
would appear in loanTBL many times. This creates what database
relationship: a
developers call a one-to-many relationship. primary key can exist
Three different types of relationships can be created between once as a primary
key on one table in a
database tables: relational database
l one-to-one l one-to-many l many-to-many. and many times as a
foreign key to link a
Database designers use a special diagram called an entity second table in the
relationship diagram (ERD) to show how the entities in the relational database
relational database are linked. many-to-many
one-to-one relationship: a
primary key can
(Principal) (School) For example, one exist many times as
school has one a primary key on one
principal. table in a relational
database and many
times as a foreign
one-to-many
key to link a second
(School) (Students) For example, one table in the relational
school has many database
students. entity relationship
diagram (ERD):
diagram that
many-to-many
For example, many illustrates the
(Subjects) (Students) relationships between
students can take
two entities in a
many subjects. relational database

170
369825_9.5_Cam_LSC_SB_160-197.indd Page 171 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Practise
Part 1
1 In Stage 8, you used data dictionaries to design suitable data tables for database models.
The following data dictionary describes the tables used to create the library-book loan
database in the ‘Learn’ box. Remember how the data dictionary includes details about
validation methods, and how input masks help to reduce the chance of a user making
an error when adding data to the database table. In the example below, you do not need
to consider validation or input masks as they are not included in the data dictionary.
studentTBL
Field name Data type Field length
*studentID Number –
studentName Short text 20
Class Short text 3

loanTBL
Field name Data type Field length
*loanID Short text 2
dateOut Date/Time –
dateBack Date/Time –
studentID Number –
bookID Short text 6
overdue? Yes/No

bookTBL
Field name Data type Field length
*bookID Short text 6
bookTitle Short text 30 The * shows the
primary keys in each
bookAuthor Short text 25
of the three tables.
a Open MS Access.
b Create a database by clicking once on Blank database, giving the database the name
libraryDB and clicking Create. A blank table will appear on screen as shown below.
View the table in Design View.

171
369825_9.5_Cam_LSC_SB_160-197.indd Page 172 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

c Name the table studentTBL and use the data dictionary on the previous page to
add the appropriate fields and data types to the table design.
d Close the table and save your changes.
2 a Click on the Create tab and select Table.
b View the table in Design View. You will be asked to give the table a name. Call the
table loanTBL.
c Add the fields and data types shown in the data dictionary for loanTBL.
d Close the table and save your changes.
3 Use the data dictionary and repeat the steps in task 2 to create the final table, called
bookTBL.

Part 2
1 Now that there are three tables for the loanDB database, you can create the
relationships between the tables. The following entity relationship diagram will help
you with this task as it shows you the types of relationships needed between the
student and loan table (one-to-many) and the book and loan table (one-to-many).

student loan book

A one-to-many relationship exists A one-to-many relationship exists


between the student and the loan between the book and the loan tables.
tables. This tells you that each This tells you that each book should
student should appear only once in appear only once in bookTBL but
studentTBL but they can appear it can appear many times in
many times in loanTBL: for example, loanTBL: for example, a book can
while the student is at the school, be loaned out many different times.
they can have many book loans.

KEYWORDS
data dictionary: table that represents the validation: automatic checks applied to individual
structure of a database table at the design stage of fields in a database table to help reduce the chance
developing a database; often contains details, e.g. of error when adding data to the table
data type, field length and details about validation input mask: control added to a field in a database
checks applied to data items table to control the format of data being added

172
369825_9.5_Cam_LSC_SB_160-197.indd Page 173 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

a Click on the Database Tools tab and select Relationships.

b Add all three tables to the Relationships window and arrange them as shown.

c Click and drag from studentID on the studentTBL to studentID on the loanTBL to
let MS Access know that you would like to create a link between the two fields. You
will be asked to edit the relationship between the two tables. Select the following
options.

173
369825_9.5_Cam_LSC_SB_160-197.indd Page 174 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Clicking on Enforce
Referential Integrity ensures
that a foreign key cannot be
added to a table if it does not
already exist in another table as
a key field. In this case, it would
stop a loan being added for a
student who did not exist in
studentTBL.

Clicking on Cascade Delete Related


Records means that if a record is deleted
from a table, then any records in another Remember: you are
table that have a foreign–primary key creating a link between
link with that table will also be deleted. the primary key in
In this case, if a student is deleted from bookTBL and the foreign
studentTBL, all loans linked to that student key in loanTBL (bookID).
in loanTBL will also be deleted.

d Repeat step c to create a one-to-many relationship between bookTBL and loanTBL.


Your relationships should now appear as shown below.

174
369825_9.5_Cam_LSC_SB_160-197.indd Page 175 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

2 Open each table in turn and add the appropriate data, shown below, to each table in
the database.
studentTBL bookTBL

studentID studentName class BookID BookTitle BookAuthor


1001 A Student 9X2 B9865 Learn P Author
Programming
1002 M Student 9X3
B8856 AI Today Q Writer
1003 P Student 9Y7
B7787 Python Programs L Expert

Be sure to add the student and the B5654 Relational P Creator


book data to the database before Databases
adding the loan data. loanTBL includes B7231 Spreadsheet J Modeller
foreign key fields and, if they have not Modelling
already been added to studentTBL and B5541 Database S Story
bookTBL, an error will occur when you Queries
try to include them in loanTBL.
B6632 Big Data B Article

loanTBL
loanID dateOut dateBack studentID bookID overdue?
L1 21 Jan 30 Jan 1001 B9865 True
L2 22 Jan 31 Jan 1002 B8856 True
L3 22 Jan 31 Jan 1003 B7787 True
L4 1 Feb 10 Feb 1001 B5654 False
L5 3 Feb 13 Feb 1002 B7231 False
L6 12 Feb 22 Feb 1001 B5541 False
L7 12 Feb 22 Feb 1001 B6632 False

3 a Open studentTBL to check that your relationship has been created correctly.
Notice the + sign to the left of each record in the table.

Click on the + sign beside


any record to see all
the loans linked to that
studentID.

b Open bookTBL and repeat


the process above to
examine the link between
bookTBL and loanTBL.

175
369825_9.5_Cam_LSC_SB_160-197.indd Page 176 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Processing data: Complex queries


Learn
Databases often contain large amounts
of data. Data stored in a database can
be processed and analysed much more
quickly than it could be by a human
processing the data by hand. One of the
ways in which data in a database can be
processed is using a tool called a query.
Queries allow users to search a database
for specific data based on search
criteria.
Queries fall into two different categories:
l Simple queries, where only a single
search criterion is used to select data
items from a database: for example,
searching a school database for all the
students who are in Stage 9 or all the
students whose age is >13.
l Complex queries, where more than
one criterion is used to search a
database, where a query is used to combine data from more than one table, or where
calculations are performed using the data in a query or a report.
Examples of complex queries include:
l parameter queries: queries where the end user provides the search criteria
l wildcard queries: queries where special characters are used to stand in for unknown
characters (this is useful when trying to find lots of data items that are similar but not
exactly the same)
l multi-table queries, which use data from more than one data table
l multiple-criteria queries, which use more than one criterion to select data items from a
database.

KEYWORDS
query: tool that allows users to search for data that report: feature in MS Access for displaying data in
meets specific rules or criteria a user-friendly format
search criterion: data item used for comparison parameter query: query where the end user
when carrying out a search provides the search criteria
criteria: set of rules that must be met wildcard query: query where special characters
simple query: where only a single search criterion are used to stand in for unknown characters (this
is used to select data items from a database is useful when trying to find lots of data items that
are similar but not exactly the same)
complex query: where more than one criterion can
be used to search a database, or a query can be multi-table query: query that uses data from more
used to combine data from more than one table, or than one data table
calculations can be performed using the data in a multiple-criteria query: query that uses more than
query one criterion to select data items from a database

176
369825_9.5_Cam_LSC_SB_160-197.indd Page 177 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Practise

Parameter queries
1 Parameter queries allow the user to enter their own data items when searching for a
data item: for example, a librarian may wish to search for a book with a specific title.
a Open LibraryDB2.accdb provided by your teacher.
b Click on the Create tab and click on Query Design.

c In the Show Table


window that appears,
double-click on
bookTBL and then
close the Show Table
window.
d Double-click on each
field in bookTBL so
that they appear in
the query field list
at the bottom of the
window.

177
369825_9.5_Cam_LSC_SB_160-197.indd Page 178 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

e Add [Please enter book title] to the Criteria row, underneath the bookTitle field.

2 a Click the Run icon in the Design tab. The following should appear.

b Enter the book title Big Data and click OK. The details regarding this book should
now be displayed.
c Close the query and save it as bookTitleQRY.
Wildcard queries It is good practice to
1 Parameter queries are ideal when the user knows include the letters QRY at
exactly what they are searching for. However, the end of the name of a new
sometimes the user may know only part of the query as it helps to distinguish
it from other objects in
search criteria, and this is when you can use
the database.
wildcard queries.
a Open LibraryDB2.accdb. Click on the Create
tab and click on Query Design.
b In the Show Table window that appears, double-click on bookTBL and then close
the Show Table window.
c Double-click on each field in bookTBL so that they appear in the query field list at
the bottom of the window.
d Add *data* to the Criteria row in the bookTitle field. Using * before and after
e Press the enter key on your keyboard. The criteria will the word ‘data’ means
now be automatically updated to read as follows: that the query will return
any record that has the
combination of letters
‘data’ somewhere in
the data stored in the
bookTitle field.

178
369825_9.5_Cam_LSC_SB_160-197.indd Page 179 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

2 a Click the Run icon to test the query. The following data items should be displayed.

b Close the query and save it with the name dataTitleQRY.


Multi-table queries
1 Sometimes it can be useful to display data from
more than one table when searching a database: You must include all
for example, if a librarian needs to see which books tables in the query design
are on loan to which students at a given time. in this way to ensure the
foreign keys will link the data
a Open LibraryDB2.accdb. Click on the Create in StudentTBL and bookTBL
tab and click on Query Design. to loanTBL.
b In the Show Table window that appears, double-
click on studentTBL, loanTBL and bookTBL and
then close the Show Table window.
c Double-click on each field in the studentTBL and bookTBL tables so that they
appear in the query field list at the bottom of the window, as shown below.

179
369825_9.5_Cam_LSC_SB_160-197.indd Page 180 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

d Click the Run icon to test the query. The following data items should be displayed.

2 a You can narrow down this search further by adding [Enter StudentID] to the
criteria for StudentID.

b Click on the Run icon to test the query and enter a studentID such as 1002 when
prompted. Close the query and save it as loansByStudentIDQRY.
Multiple-criteria queries
1 Multiple-criteria queries search records using two or more You have now
data items as search criteria. The search criteria can be combined a multi-
provided by the user as parameters or can be added into table query with a
the query design under the criteria heading. parameter query.
For example, a librarian may want to search for all the
books loaned out to a particular student, which are also
overdue.
a Open LibraryDB2.accdb. Click on the Create tab and click on Query Design.
b In the Show Table window that appears, double-click on studentTBL, loanTBL and
bookTBL and then close the Show Table window.
c This time, double-click on each of the fields in all three tables to include them in the
query.
d Add the following criteria to the query design.

180
369825_9.5_Cam_LSC_SB_160-197.indd Page 181 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

e Notice how some data items appear twice in this query. You can stop data items
from displaying when you run a query by unticking Show. Remove the tick from
underneath the overdue? field.
2 a Click on the Run icon to test your query. Enter the studentID 1001 when prompted.
The following results should appear.

b Close your query and save it as overdueByStudentQRY.

Computational thinking – abstraction


1 a D iscuss with your partner how you can create
a query to search libraryDB2 for a list of books
about programming taken out by student 1003 You may want to use a
that are overdue. parameter to enter studentID
b Save your query as programOverdueQRY. so that you can use the
query again with a different
2 Look carefully at the book names in bookTBL in
studentID at a later stage.
the file libraryDB2.accdb. Do the titles of all the
books contain the full word ‘programming’ or do
some titles include abbreviated terms that relate to
programming (for example, the book title Python Programs)? How could you use a
wildcard query to search the book titles?
3 Think about the criteria you need to enter to search for books that are overdue. If the term
date() can be used to insert today’s date as a database search criteria, how could this
term be used to develop a query that produces a list of all the books that are overdue?

Creating spreadsheet models


Learn
As you’ve explored in previous stages,
spreadsheets can be used to analyse data
and improve how it is presented. A
spreadsheet can perform calculations and,
if the values are changed, it can work out
the new results automatically. This is an
advantage because it means that you can
try lots of values and see the new results.
As the calculations are done so quickly, you
can spend time focusing on the results and
thinking about how they are affected by
changes to the data values. In other words,

181
369825_9.5_Cam_LSC_SB_160-197.indd Page 182 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

you can predict what would happen if you made certain changes. Spreadsheets can be
used to collect and store large amounts of data in rows and columns.
Spreadsheet software can be used to make decisions in real life. The spreadsheet can be
used to create a model of a real-life event and the relationships between different factors
in that event. For example, when creating a spreadsheet model to represent the costings
associated with organising a birthday party, there is a link between the overall cost of the
party and the number of people invited: as the number of people attending increases,
so too does the cost of the party. By changing data or a formula in the spreadsheet, it
is possible to see how certain data items in the model affect other data items and the
output. Spreadsheets contain a wide range of tools and special functions that can be used
to explore the links between data items.
Some of the MS Excel functions you will already be familiar with include SUM and AVERAGE.
For example, the Geography department in school created the model below to record
temperature and rainfall in a location over a period of one week. They used formulae to
calculate the average temperature and rainfall over seven days and the total rainfall in that
period of time.

=SUM (C2:C8)

=AVERAGE(B2:B8)

Additional functions can be used to help with the analysis of data in a spreadsheet model.
These include the following.

Function Purpose Example


MIN Returns the lowest value in a specified range of cells =MIN(B2:B8)
MAX Returns the highest value in a specified range of cells =MAX(B2:B8)
IF Evaluates a condition and displays one value in a cell if the =IF(C2>0,"There was rain
condition is True and an alternative output if the condition is False today", "There was no
rain today")
COUNT Checks all the cells in a specified range and outputs how many =COUNT(B2:B8)
contain a numerical value

182
369825_9.5_Cam_LSC_SB_160-197.indd Page 183 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

KEYWORDS
function: sub-program that can exist as part of a IF statement: in Python, this evaluates a condition
bigger program which determines the path of the program
MIN function: returns the lowest value in a depending on whether the condition is true or false
specified range of cells in a spreadsheet COUNT function: checks all the cells in a specified
MAX function: returns the highest value in a range in a spreadsheet and outputs how many
specified range of cells in a spreadsheet contain a numeric value

Practise
1 Expand the Geography department’s
weather model. This model contains
the rainfall, temperature readings
and estimated percentage ( % ) cloud
coverage over a period of 28 days. Edit
the formulae to calculate the highest
temperature and rainfall level in a 28-day
period by following these steps using the
functions described in the ‘Learn’ box.
a Open the file Weather.xlsx provided by
your teacher.
b Edit the model to add the additional
label ‘Highest’ in cell A30.
– Add the formula =MAX(B1:B29) to
cell B30.
– Press enter to display the highest
temperature recorded in the 28-day
period.
c Copy the formula you created in part b
into cell C30 so that you can now also
calculate the highest rainfall level in the
28-day period.
2 With your partner, work out how you
can use the MIN function in cells B31 and
C31 to calculate the lowest temperature
and lowest rainfall in the 28-day period
in the Weather.xlsx model. Add the
label ‘Lowest’ to cell A31 to ensure that anyone viewing the
spreadsheet data can easily understand what the new data On days that there
items represent. were no clouds in
3 In Stage 8, you were introduced to the AVERAGE spreadsheet the sky, the teacher
function. Edit the formula to calculate the average temperature in recorded ‘No Clouds’
a 28-day period using the AVERAGE function. in column D.
– Add the label ‘Average Temperature’ to cell A32 and then use
a formula in cell B32 to calculate the average temperature in the 28-day period.
– Display the average temperature to 2 decimal places.

183
369825_9.5_Cam_LSC_SB_160-197.indd Page 184 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

4 Edit the formula to calculate the


number of cloudy days using the
COUNT function.
a In cell A33, add the label ‘Cloudy
Days’.
b In cell D33, add the formula
=COUNT(D2:D29) and press
enter. This will display the
total number of days where a
numerical value was entered into
a cell in the range D2 to D29;
that is, the number of days when
clouds were seen in the sky.
5 The Geography department
have decided that if the average
temperature is over 24 degrees in a
28-day period then that month can
be classified as ‘Very Hot’. Edit the
formula to calculate temperature
analysis using the IF function.
a In cell A34, add the label
‘Temperature Analysis’.
Add the following IF statement
to cell B34 and then press
enter.
The IF statement has three main
parts:
=IF (B32>24, "Very Hot", "Mild Temperature")

The condition. What happens if What happens if


the condition is the condition is
True. False.

b Save your updated spreadsheet by selecting File and Save.

184
369825_9.5_Cam_LSC_SB_160-197.indd Page 185 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Computational thinking – algorithms


1 Discuss with your partner how you could make the following changes to the model.
– Display ‘Very Hot’ in cell B34 if the temperature was 22.09 or above.
– Display text in cell D34 that says ‘Cloudy month’ if the number of Cloudy Days is 16
or above, but ‘Not cloudy’ if the number of Cloudy Days is <16.
2 Use the symbols below to create a flowchart that can help you to plan your Cloudy
Day IF statement.
This spreadsheet structure could also be used to illustrate the operation of the ‘Very
hot’ IF statement already used in cell B34.

Start End

Evaluating models that represent real-life systems


Learn
Evaluation is an especially important
part of the development of models that
represent real-life systems. The process
of evaluation involves checking that
a solution that has been developed
actually solves the problem it has been
designed for, and it also involves making
sure that the solution works correctly
and efficiently.
Evaluation is something you do all the
time. For example, in your day-to-day life
you evaluate the movies you watch, the
computer games you play, the activities
you are involved in and even lessons or learning experiences in the classroom. You can
think of evaluation as passing judgement at the end of a process or experience. In the
digital world, however, you can think of evaluation as a continuous activity (it happens at
all stages in the design, development and testing of a solution).

185
369825_9.5_Cam_LSC_SB_160-197.indd Page 186 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

When developers are asked to create a new solution to a problem, they are often
presented with a set of user requirements. User requirements are a list of the things that
the new digital solution is meant to include. They can involve comments on the colour
scheme for a new webpage, a list of queries that a database is expected to produce or a
list of questions that need to be answered by a spreadsheet model.
Evaluation can take place at different stages in the development of a digital solution, and
how the evaluation is carried out often depends on the type of solution being developed
for a problem: for example, a database solution would be evaluated in a different way
from a spreadsheet solution to a problem. When evaluating a database solution, it is
important to ensure that queries used to extract data can successfully provide the
user with the data they require from the database model of a real-life scenario. When
evaluating a spreadsheet model of a real-life scenario, it is not only important to ensure
that the spreadsheet is a suitable model for the real-life scenario, for example, by ensuring
that it includes all the required data items, but it is also important to ensure that the
results produced by formulae in the spreadsheet model are accurate.
The following table gives some of the key points to consider when evaluating database
and spreadsheet models.

Evaluating solutions
Does the solution meet all the user requirements?
Evaluating the suitability of a database model Evaluating the suitability of a spreadsheet model
✔ Does it include all the queries needed to answer the ✔ Does the spreadsheet include all the factors linked to
user’s questions? the scenario it is modelling?
✔ Do the queries produce the correct results? ✔ Are the factors all displayed in the correct data
✔ Does the model include all the important factors format?
linked to the scenario it is modelling? ✔ Are the correct factors in the model linked by
✔ Are all the data items in the model displayed using formulae?
the correct data type? (This will ensure that the ✔ Do the formulae output the correct results?
data is presented to the user in the correct format ✔ Can you make any improvements to the data model?
and that it can be processed correctly.)
✔ Can you make any improvements to the data model?
✔ Are there any easier ways of allowing the user to
query the database (e.g. instead of creating a query
for every title in the book database in a library,
could you use a parameter query instead)?

KEYWORDS
evaluation: checking the suitability of a solution to a problem
efficient: the efficiency of a program can be measured by how quickly it
runs
user requirements: tasks a user expects of an application
data type: classification applied to a data item specifying which type of data
that item represents, e.g. in a spreadsheet some of the data types available
include currency, text and number

186
369825_9.5_Cam_LSC_SB_160-197.indd Page 187 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Practise
Evaluating a database model
In this task, you will evaluate the suitability of pre-existing database and spreadsheet
models of two real-life scenarios to ensure that they accurately represent the real-life
systems. As part of your evaluation, you will determine whether the models are suitable
for purpose in each instance.
1 Open the file LibraryDB2Evaluate.accdb provided by your teacher. It should cover the
following user requirements.

The database is to be used by the school librarian to help them to keep track of books
on loan to students at any given time. They have said that the database model should:
l store details about members of the library (students), so that they can be
contacted if their books are overdue
l work out how many days a book is overdue
l allow users to create a list of all the books borrowed by a student
l allow users to search for books by book title
l allow users to search for books by author name.

With your partner, evaluate the database against the user requirements above.
Check the following:
– That the database meets each of the user requirements. (Do the queries produce
the correct results?)
– Whether the queries work in the most efficient manner. (Can you think of a better
way of searching for the data?)
– Whether the database structure is correct: for example, are the correct data types
assigned to all fields, and are the field lengths appropriate?
2 As you evaluate the database, make a list of any of the requirements it does not meet,
and any improvements you would make to the design.
Evaluating a spreadsheet model
The Geography department have developed a spreadsheet model that shows the level of
traffic on a local road.
1 Open the file Traffic Evaluate.xlsx. It should cover the following user requirements...

The spreadsheet should show:


l the total number of vehicles travelling along the road in one month
l the average number of cars, motorcycles and lorries travelling along the road in
one month
l the total number of days each month when motorcycles travelled along the toad
l the highest number of motorcycles and cars travelling along the road in one day
l an alert that reads ‘Busy Road’ if the total number of vehicles travelling along
the road in one month is greater than 1000.

187
369825_9.5_Cam_LSC_SB_160-197.indd Page 188 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

2 With your partner, evaluate the spreadsheet against the user requirements.
As you evaluate the spreadsheet model, check the following:
– Does the model contain all the factors needed to generate a full picture of the scenario?
– Does the model meet each of the user requirements? (As you evaluate the
spreadsheet, make a list of any of the requirements it does not meet.)
– Do the formulae produce the correct results? (Correct any formula you find to be
incorrect in the model and re-save your copy of Traffic Evaluate.xlsx).
– Is the data formatted in the correct manner?
3 Correct any formula you find to be incorrect in the model.
4 Remember to save your updated spreadsheet at the end of the task.

Go further
Databases
Database queries can be used to generate additional data items: for example, a librarian
can compare today’s date with the dateBack date in the libraryDB to work out how many
days a library book is overdue.
1 Open LibraryDBGF.accdb provided by your teacher. Create a new query containing
the following data items and criteria.

Note how the criteria for overdue? has been set to True. You use
the criteria True as you want only to display those records where
the book is overdue.

2 In the Field row, to the right of overdue?, add DaysOverDue:Date()-[dateBack] to the


next available column in the spreadsheet query.

188
369825_9.5_Cam_LSC_SB_160-197.indd Page 189 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

The instruction you are adding to the field row has three main parts.
DaysOverDue: This is the name of the new field you are creating as part of this query
Date() This is a special function that will insert today’s date into the equation
-[dateBack] This is an instruction that tells the query to subtract the value stored in
the dateBack field in the database from today’s date

3 Run your query to test that it


works correctly. Results similar Note that your days overdue will be different as
to the ones shown below will the date added using Date() will be different.
appear.

4 Save your query as daysOverdueQRY.


Spreadsheets
In the ‘Creating spreadsheet models’ section, you learned how to use conditions in IF
statements to determine the content of a cell in a spreadsheet model. IF functions can
also be used to combine more than one condition at a time.
The Geography department would like to add a new column to the weather model from
the previous section, to give advice to students about the weather.
The column will examine ‘CloudCover’ and ‘Rainfall’ each day and will display the words
‘Umbrella needed’ in column E if there is more than 2 mm of rainfall OR if cloud cover is
20 or higher.
1 Open Weather GF.xlsx provided by your teacher. Add the heading ‘Weather Advice’
to cell E1.
2 In cell E2, add the formula =IF(OR(D2>=20,C2>2),"Umbrella needed","").

The Boolean operator is outside Notice how the two conditions


the brackets. are inside round brackets and
separated by a comma.

189
369825_9.5_Cam_LSC_SB_160-197.indd Page 190 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

You can use "" to indicate that you do not want to display anything.

=IF(OR(D2>=20,C2>2),"Umbrella needed","")

The structure of the rest of the IF statement remains


unchanged; it is still contained inside ( ) and the two outcomes
that depend on the condition are still separated by commas.

3 Press enter to test your formula. The words ‘Umbrella needed’ should appear in cell E2.
4 Replicate this formula to the rest of the cells in column E.
5 The Geography teacher realises that they have made a mistake with the formula and
that the words ‘Umbrella needed’ should be displayed only if the cloud cover is >=20
AND rainfall is >=2. Amend the formula in column E to reflect this change.
6 Save your updated version of the spreadsheet as Weather GF.xlsx.

Challenge yourself
Databases
Most relational database applications, such as MS Access, use
a special programming language called Structured Query
Language (SQL) to access the data stored in data tables. The
method you have used to create queries up until now is known
as Query by Example (QBE).
In exceptionally large databases, queries created using SQL
are processed more rapidly than those created using the
QBE method. This could be particularly important when the
library database becomes larger in size and the librarian is,
for example, answering queries on book availability at a time
when the library is very busy.
Create a query to search bookTBL for all the books written by
P Author.
1 Open LibraryDBCY.accdb provided by your teacher.
2 Click Create and then Query Design.
3 Close the Show Table dialogue box that appears on screen. Click View and then select
SQL view.
4 Add the following statement to the SQL query window.
SELECT [bookID], [bookTitle], [bookAuthor]
FROM bookTBL
WHERE [bookAuthor] = "P Author";

190
369825_9.5_Cam_LSC_SB_160-197.indd Page 191 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

5 Click Run to test your query.


6 Save your query as P AuthorQRY.
Spreadsheets
The Geography department in your school have asked you to expand the weather model
you produced in the ‘Creating spreadsheet models’ section.
Your teacher will provide you with a file called Weather CY.xlsx to allow you to complete
this task, which uses a new spreadsheet function called COUNTIF.
COUNTIF can be used to extract more specific information from a spreadsheet. For
example, in the weather model, it could be used to count the number of days when:
l rainfall was greater than 5 mm
l CloudCover was >15 Normally, only text values
l there were no clouds.
need to be enclosed in double
quotation marks ( " " ), and
1 Edit the weather spreadsheet and expand the
numbers do not, but when a
spreadsheet to contain the additional information logical operator is included with
described above. Open Weather CY.xlsx provided by a number, double quotation
your teacher. marks are needed.
2 In cell H3, add =COUNTIF(C2:C29, ">5") and press enter.

3 Add a similar COUNTIF formula to cell H4 to count the number of days when cloud cover
was >15, and to cell H5 to count the number of days there were no clouds in the sky.
When you press enter, the following values should appear:
– Cell H4 = 9
– Cell H5 = 12
4 Resave your updated spreadsheet.

191
369825_9.5_Cam_LSC_SB_160-197.indd Page 192 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

KEYWORDS
Structured Query Language (SQL): specialised language for accessing data
in relational databases
Query by Example (QBE): interface that allows users to select fields and
criteria for use in a query in a database application

Final project
Look back to the start of this unit to remind yourself of the Scenario. You now have
all the skills and knowledge you need to create a spreadsheet and database model
that can help the school to create and evaluate models that represent students’ and
teachers’ use of the new VLE.
Compete the tasks below.
Part 1: Big Data
After hearing about the term Big Data, the school are worried that the data generated
by the new VLE will be too complex to be analysed.
1 Produce a report that explains what is meant by the term Big Data.
2 In your report, explain what is meant by Big Data in terms of the 5Vs; also provide
examples to illustrate how Big Data is used in some real-life applications.
3 At the end of the report, comment on whether the VLE data can be considered an
example of Big Data; also explain why you think this is the case.
Part 2: The database

The school have asked you to help them create a relational database that will keep
track of information such as:
l a list of all the pages accessed using any of the following devices: PC, laptop,
mobile phone, tablet
l a list of all student logins and passwords
l a list of all teacher logins and passwords
l a list of all teachers and the subjects they teach
l a list of all user logins and the times they have accessed any page from a
selected subject
l a list of all the pages accessed by a teacher for updating; the list should include
information about when and on what type of device the page was accessed.

Your teacher will provide the file FinalProject.accdb for these tasks. The file contains
three tables and some of the data used to create a real-life model of teacher and
student use and access of the VLE. The tables contain:
l a list of users and details about the users
l a list of pages and information about the pages
l a list of times each page is accessed and information about who accessed the page
and why they accessed it.

192
369825_9.5_Cam_LSC_SB_160-197.indd Page 193 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

1 Open the file FinalProject.accdb.


a Open each table in the database and identify the primary key in each table (make
a note of the primary keys in writing).
b Look carefully at each table and identify any primary keys used as foreign keys in
another table (make a note of the foreign keys in writing).
2 a Click on the Database Tools tab in the database and click on Relationships.
b Use your notes on primary and foreign keys to create relationships between the
three tables in the database.
c Save your updated copy of FinalProject.accdb.
3 Use your relational database to create queries to enable the school to find the
following information.
a A list containing the pageTitle, subjectName, pageType and dates and times when
any History pages were accessed; save this as query3a.
b A list containing the pageTitle, subjectName, pageType and dates and times when
any History pages were accessed on a laptop; save this as query3b.
c A list containing the userLogin, userType, pageTitle and subject of any Stage 7
pages that have been updated; save this as query3c.
d A list of all the data from pageAccessTable that shows when teacher3 accessed
the VLE to update pages; save this as query3d.
e A parameter query that will allow the school to search for the date, time and page
title of the pages accessed by a userLogin; save this as query3e.
f A list of dates and times when teachers have accessed a markbook page on the VLE ;
save this as query3f.
g A list of all the dates and times when times students have accessed a multimedia
tutorial page on the VLE; save this as query3g.
h Save your updated copy of the database.
4 The school would also like to use the relational database model FinalProject.accdb
to keep track of how well the school VLE is being used by teachers and students.
Create queries in your database model that will also allow the school to do the
following (assign appropriate names to each query).
a Create a list of all the pages accessed using a mobile phone or tablet.
b Produce a list of all student logins and passwords.
c Produce a list of all teacher logins and passwords.
d Create a list of all teachers and the subjects they teach. (Think carefully about this
query; does the database contain enough information about each teacher to allow
you to create this query?)
e Produce a list of all user logins and the times when they accessed VLE pages that
relate to a subject which is specified by the user.
f Create a list of all the pages accessed by a teacher for updating, including
information about when and on what type of device the page was accessed.
Remember to save your updated database.
5 a Evaluate the database model FinalProject.accdb, including the queries you created
in tasks 3 and 4. Produce a word-processed report that comments on the following.
– How complete is the data model? (Does it include all the data needed to allow
the school to generate the new lists described above?)

193
369825_9.5_Cam_LSC_SB_160-197.indd Page 194 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

– Are there any improvements to be made to the designs of any of the queries
completed in Part 3?
– Review each of your queries in design view and look for any data items that are
not needed according to the query description provided in the task.
– Are there any queries that could be reused if a parameter query were used
instead of providing the data in the query design?
b Make the appropriate changes to your query design and save your updated
version of FinalProject.accdb.
Comment on the changes you have made in your report.
In your report, suggest three more possible queries that could be created using
the data available in the current model. List the field headings and the criteria
needed in each query.
Part 3: The spreadsheet
Your teacher will provide the file FinalProject.xlsx for these tasks. This spreadsheet
contains two worksheets:
l The first is a copy of some of the data exported from FinalProject.accdb and relates
to teacher and student access to the VLE pages (AccessData tab).
l The second is to help the school understand how some of the VLE pages are being
used by teachers and students (Dept Summary Spreadsheet tab).
1 a Examine the Dept Summary Spreadsheet tab in FinalProject.xlsx. Comment on
how effective this model is in helping the school model the VLE access so that
they can answer the following questions:
– What is the most popular time of day for students to access a VLE page?
– How long, on average, do teachers spend updating the VLE pages?
– What is the longest period of time spent on a Drama VLE page?
– How many minutes in total were spent on a Drama VLE page?
– How many times were the Computing VLE pages accessed in total?
– What is the average length of time spent on the Computing VLE pages?
– How many hours in total were spent on the Computing and Drama VLE pages?
– What was the shortest length of time spent on the Computing and Drama VLE
pages?
b Write a short report that comments on the effectiveness of the model in
addressing each of these questions. Comment on:
– any changes you think need to be made to formulae
– any additional formulae that need to be added
– any additional data items needed to answer the questions.
c Make any necessary changes to the spreadsheet formulae to ensure that the data
output is correct.
2 a Create a new sheet in FinalProject.xlsx. Do this by clicking on the + sign at the
bottom of the existing worksheet in your spreadsheet. Double-click on the new
tab and rename it ‘Teacher Student Access Summary’.

194
369825_9.5_Cam_LSC_SB_160-197.indd Page 195 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

b Copy and paste the data from the Access Data tab into Teacher Student Access
Summary.
c Sort the data in the spreadsheet so that it is displayed in order of userType.
i Click on the first label in the spreadsheet.
ii Select the Data tab and click on Sort.
iii Select Sort by userType and click on OK.

3 Add appropriate formulae to your spreadsheet to allow the school to extract the
following data from your model:
– The average number of minutes spent on the VLE by students
– The average number of minutes spent on the VLE by teachers
– The number of minutes spent accessing the VLE in total by both students and
teachers
– The total number of times the VLE was accessed by students
– The total number of times the VLE was accessed by teachers
– The longest period of time spent on any VLE page by a student
– The longest period of time spent on any VLE page by a teacher
– The longest period of time spent on any VLE page by either a student or a teacher
– The shortest period of time spent accessing a VLE page by either a student or a
teacher
– An output message that states ‘High Level of Use’ if the total time spent accessing
the VLE is over 200 minutes, or outputs the message ‘We need to encourage more
use’ if total access time is 200 minutes or less.
4 Save your updated version of FinalProject.xlsx.

195
369825_9.5_Cam_LSC_SB_160-197.indd Page 196 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Evaluation
Part 1: Big Data
1 Swap reports with your partner. Check that your partner has:
a correctly explained what the term Big Data means
b described Big Data correctly in terms of the 5Vs
c provided examples of how Big Data is used in a number of real-life applications
d commented on whether the data used by the school in developing real-life models
of their VLE scenario would be an example of Big Data.
2 Make changes to your report following your partner’s feedback.

Part 2: The database


1 Swap FinalProject.accdb with your partner.
Use this list to check that your partner has correctly created an appropriate
relationship between each of the tables in their database.

l A list containing the pageTitle, subjectName, pageType and dates and times
when any History pages were accessed; saved as query1.
l A list containing the pageTitle, subjectName, pageType and dates and times
when any History pages were accessed on a laptop; saved as query2.
l A list containing the userLogin, userType, pageTitle and subject of any Stage 7
pages that have been updated; saved as query3.
l A list of all the data from pageAccessTable that shows when teacher3 accessed
the VLE to update pages; saved as query4.
l A parameter query that allows the school to search for the date, time and page
title of the pages accessed by a userLogin; saved as query5.
l A list of all the pages accessed by students in each stage in school.
l A list of times when teachers have accessed a markbook page on the VLE.
l A list of all the times when students have accessed a multimedia tutorial page on
the VLE.

2 Check that your partner has also:


– created a list of all the pages accessed using any of the following devices: PC,
laptop, mobile, tablet
– produced a list of all student logins and passwords
– produced a list of all teacher logins and passwords
– created a list of all teachers and the subjects they teach
– produced a list of all user logins and the times when they accessed any page from a
selected subject
– created a list of all the pages accessed by a teacher for updating.
3 Update your copy of FinalProject.accdb based on your partner’s feedback.

196
369825_9.5_Cam_LSC_SB_160-197.indd Page 197 06/03/23 9:53 AM A4902 /142/HO02737/work/indd

Unit 9.5 Big Data modelling and analysis: Databases and spreadsheets

Part 3: The spreadsheet


1 Swap FinalProject.xlsx with your partner.
a Evaluate the Dept Summary Spreadsheet worksheet to ensure that it can be used to
produce the following data correctly:
– How long, on average, do teachers spend updating the VLE pages?
– What is the longest period of time spent on a Drama VLE page?
– How many minutes in total were spent on a Drama VLE page?
– How many times were the Computing VLE pages accessed in total?
– What is the average length of time spent on the Computing VLE pages?
– How many hours in total were spent on the Computing and Drama VLE pages?
– What was the shortest length of time spent on the Computing and Drama VLE pages?
b Evaluate the Teacher Student Access Summary tab to ensure that it can be used to
produce the following data correctly:
– The average number of minutes spent on the VLE by students
– The average number of minutes spent on the VLE by teachers
– The number of minutes spent accessing the VLE in total by both students and
teachers
– The total number of times the VLE was accessed by students
– The total number of times the VLE was accessed by teachers
– The longest period of time spent on any VLE page by a student
– The longest period of time spent on any VLE page by a teacher
– The longest period of time spent on any VLE page by either a student or a
teacher
– The shortest period of time spent accessing a VLE page by either a student or a teacher
– An output message that states ‘High Level of Use’ if the total time spent
accessing the VLE is over 200 minutes, or outputs the message ‘We need to
encourage more use’ if total access time is 200 minutes or less.
2 Update your copy of FinalProject.xlsx based on feedback provided by your partner.

What can you do?

Read and review what you can do:


4 I can evaluate the use of models that represent real-life systems.
4 I can use functions in spreadsheets to analyse data, such as IF, MIN, MAX, COUNT.
4 I can create spreadsheets that model real-life systems.
4 I can evaluate the suitability of a spreadsheet for given purposes.
4 I can create relational databases with two or more linked tables.
4 I can create complex searches for data in databases using two or more criteria.
4 I can create complex searches in relational databases.
4 I can explain the term Big Data and describe its applications.

197
369825_9.6_Cam_LSC_SB_198-235.indd Page 198 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit
9.6 An array of skills

Get started!
Consider a very simple game that requires you to navigate a player from one place to
another to collect an item. In the example below, the smiley face needs to move from its
current position to collect the apple.
The smiley face can understand only the commands:

The first command would be:

Discuss the following with your partner:


l What commands are needed to get the smiley face from its starting point to the apple?
l Are there patterns in your solution?
l How could you group some of the similar commands together to make your program
more efficient?
Identifying patterns in solutions allows you to make programming code more efficient
and to reuse code when needed in other parts of your programs.
In this unit, you will build on your Python programming skills, using iteration and arrays to
store, find and retrieve data to create solutions to problems. You will continue to develop
your knowledge and skills of coding in Python to create programs that use sequence,
selection and iteration to solve a variety of problems.

198
369825_9.6_Cam_LSC_SB_198-235.indd Page 199 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Learning outcomes
In this unit, you will learn to:
l identify and explain the purpose of a one-dimensional array
l develop a Python program with count-controlled loops
l access data from an array using Python
l develop Python programs using string manipulation, including length, uppercase and
lowercase
l use iterative development on Python prototypes to create solutions to problems
l develop and apply test plans using test data that is normal, extreme and invalid
l identify and describe a range of errors, including syntax, logic and runtime errors
l use a trace table to debug a Python program
l follow, understand, edit and correct algorithms that are presented as pseudocode
l use a sub-routine in flowcharts or pseudocode
l explain and use iteration statements with count-controlled loops in either pseudocode
or flowcharts
l predict the outcome of algorithms that use iteration.

Warm up
In pairs, consider the following list of numbers:
7, 19, 3, 11, 20, 65, 2, 34, 41, 14
How would you find out whether the number 34 is in this list? Think about the following
questions:
l Which number would you check first?
l What would you do if the first number that you check is not the number you are
looking for?
Now consider the same set of numbers, but ordered from smallest to largest:
2, 3, 7, 11, 14, 19, 20, 34, 41, 65
How would you find out whether the number 41 is in this list?
l Would you use the same method as you used for the list above?
l Can you think of another way to check for the number?

To complete these tasks, you have used data that is stored in a list. In this unit, you will
learn how to search through lists to retrieve data to use in your programs.

199
369825_9.6_Cam_LSC_SB_198-235.indd Page 200 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

SCENARIO
A local primary school has asked you to develop a game that can be used to teach younger students
their times tables. They want the program to be an adventure-style game that asks the students
questions based on a scenario to help their problem-solving skills. The game should follow these criteria:
l When the game starts, the player will need to log in using their name, and input their age as
they must be between 7 and 10 years old to play the game.
l They will then pick the character they want to play as and choose the times table that they
want to practise.
l The game will need to ask the player five multiplication questions that are phrased as
sentences. For example, instead of 2 × 5 it would ask questions such as ‘In the cave you see 2
chests each containing 5 coins. How many coins do you have?’
l The player will get two attempts to answer each question. If they get it right first time, they
will receive 2 points. If they get it right second time, they will receive 1 point. Otherwise, they
will receive 0 points.
l After the five questions have been asked, users will be given a score to indicate how well they
have done, including how many correct answers they got and how many they got right at the
first attempt.
As you work through this unit, you will be given flowchart and pseudocode algorithms and
examples of Python code to enable you to complete the tasks. You will also create new code, edit
code, design solutions using algorithms and test the program to make sure that it works correctly.

Do you remember?
Before starting this unit, you should be able to:
✔ identify and describe different data types that are used in Python
✔ predict and test the outcome of different algorithms
✔ break problems down into smaller sub-problems
✔ use program libraries to add additional functionality to programs
✔ develop programs that make use of selection
✔ develop programs that use different data types
✔ develop programs that use different Boolean operators
✔ refine and develop programs using iterative processes
✔ identify appropriate test data to ensure that programs work as expected.

In this unit, you will use the Python programming language.

Python’s Integrated Development and Learning Environment (IDLE) provides features for
creating, editing and running programs. Before using Python, you will need to install IDLE
on your own personal device.
1 Go to www.python.org/downloads
2 Select Download Python.
3 Once downloaded, double-click on the file to open it and then choose Install Now.
4 Once IDLE has installed, it should appear in your Start Menu.

200
369825_9.6_Cam_LSC_SB_198-235.indd Page 201 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Breaking it down: decomposition and sub-programs


Learn
In previous units, you recapped the different stages of an iterative development process
and used repeated cycles to develop programs. Here’s an overview of the process.

The first stage is planning, where the problem is decomposed into the different sub-
problems that need to be solved and the requirements of the finished product are identified.

The algorithms are then designed, and the program is developed and tested. At the
end of the cycle the work is reviewed and evaluated before the next cycle begins.

In Stage 8, you also learned how to use sub-programs in Python, so that each sub-
problem could be written as a mini-program. The sub-programs were combined to make
the finished program.
Here’s a recap.

In Python, a sub-program is created, or defined, by writing the keyword def followed


by the name you want to call the sub-program, followed by parentheses and a colon.
All sub-programs are written before the main program, for example:

To run the sub-program, it is called by writing its name followed by parentheses in the
main program. The main program is written below all the sub-programs.

You will be using sub-programs and an iterative process throughout this unit to develop
your program code.

KEYWORDS
iterate/iterative/iteration: repeat/repeated/repetition
program: instructions that tell a computer system how to complete a task
user requirements: tasks a user expects of an application
algorithm: step-by-step instructions to solve a particular problem
sub-program: small program that can be called from the main program to
run at any time

201
369825_9.6_Cam_LSC_SB_198-235.indd Page 202 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Decompose the problem presented in An
the Scenario at the start of this unit to example of a sub-
identify the different sub-programs program that will be needed
that will be needed. is the process of generating the
2 Write a list of the requirements for each sub-program. question to be asked.
3 Evaluate and compare your list with your partner.
a Have you broken down the problem into similar
sub-programs that will need writing?
b Are your program requirements the same?
4 What are the benefits of developing a program Think
using decomposition and iterative development? about the size
of the problems once
5 Discuss with your partner:
they have been decomposed
a What is the next stage in the program and the complexity of them
development process? compared with one single
b How will you know if your program code is program
working correctly?
c What is the final stage in the program
development process?

User login: it’s all in the loops


Learn
The first sub-task that you should have identified (in the
previous ‘Practise’ tasks) is the need for the player to log in.
A login system is a common type of program that makes
use of iteration. A user is normally allowed a set number of
attempts to log in before they are locked out or prevented
from trying again for a period of time.
To allow a user to have repeated attempts to log in to a
system, the program code needs to use iteration to run the
block of code several times. To do this, the program uses a
count-controlled loop.
As you’ve explored in previous units, a count-controlled loop allows a block of code to be
repeated a set number of times. Remember that, in Python, these are often referred to as
for loops as they begin with the keyword for.

202
369825_9.6_Cam_LSC_SB_198-235.indd Page 203 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

The range() states the number of times that the indented code below will be repeated.
The following program loops three times.

The word ‘Hello’ is printed to the screen each time the


code repeats.

In the example above, ‘counter’ is a variable that keeps track of how many times the code
has repeated. It starts with the value 0 and is increased by 1 each time the code is run.
The loop ends when its value matches the number set in the range. The loop variable can
have any name you choose, and it is sensible to use a name that relates to the data that it
is storing.
The following program prints out the value of the loop variable; in this case, ‘number’.

The output shows that the loop


variable starts at 0.

However, you can add another parameter if you want to specify the starting value for the
count: for example, range(11, 16) means values from 11 to 16 (but not including 16), so
the program below will print out the numbers from 11 to 15.

203
369825_9.6_Cam_LSC_SB_198-235.indd Page 204 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Remember: writing count-controlled loops in


pseudocode is very similar to writing the Start

actual program code in Python. You use the


keyword for, and then put how many times
count = 1
you want the code to be repeated. This
example would repeat the code ten times.
FOR count = 1 to 10
OUTPUT count Yes
is count == 11? Stop
ENDFOR

If you want to show a count-controlled loop


No
in a flowchart, you need to include the loop
variable and show where it is incremented.
The flowchart algorithm shown here does the OUTPUT count
same as the pseudocode algorithm above.

count = count + 1

The pseudocode below shows the algorithm for a login system. The user is given three
attempts to log in, and to access the game they must enter the name ‘Superstar’.
SUBPROGRAM login ()

username = "Superstar"
entry = ""
count = 0

FOR attempt = 1 to 3
entry = INPUT
count = count + 1
IF entry == username THEN
PRINT "Welcome to the game"
BREAK
ELSEIF count < 3 THEN
PRINT "Try again"
ELSEIF count == 3 THEN
PRINT "3 incorrect attempts. You are locked out."
EXIT()
ENDIF
ENDFOR

ENDSUBPROGRAM

204
369825_9.6_Cam_LSC_SB_198-235.indd Page 205 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Key elements of the pseudocode include the following.


l count: This keeps track of how many times a username has been entered. It is used to
give appropriate feedback after each incorrect attempt.
l BREAK: This breaks out of the loop. It is used when the correct username has been
entered to prevent the player from being asked to enter it again. In Python, you add the
keyword break as a single line of code at the point where you want to exit the loop.
l EXIT(): This code indicates that the program should stop running at this point. It is
used here because the game should not continue if the username has been entered
incorrectly three times. In Python, you use the function exit() at the point in the
program where you want it to finish.

KEYWORDS
login system: method of accessing different systems using a username and/or password
iterate/iterative/iteration: repeat/repeated/repetition
count-controlled loop: set of instructions repeated a set number of times
variable: named memory location that can store a value
loop variable: variable that counts the number of times code has been repeated in a count-controlled loop
data: raw facts and figures
parameter: value that is passed into a function to be used as part of a sub-program
pseudocode: textual representation of an algorithm
flowchart: visual representation of an algorithm
incremented: when the value of a variable is increased by 1
function: sub-program that can exist as part of a bigger program

Practise
1 Write a flowchart algorithm for a program to do the following.
– Ask the user to enter their name and store it in a variable ‘name’.
– Ask the user to enter their age and store it in a variable ‘age’.
– Use a count-controlled loop to print out five times a sentence that includes the
user’s name and age.
2 Open a new program file in Python. Create the code for your flowchart. Use two
variables to store your name and age. Use a count-controlled loop to print out a
sentence five times that includes your name and age.
3 Using the pseudocode in the ‘Learn’ box, create the login system for the prototype
Times Table Adventure game. Write the login system as a sub-program called login().
The sub-program should:
– allow the player to enter a username
– check whether the username entered matches the one stored in the program
– give the user three attempts to enter the correct username
– give appropriate feedback after each attempt
– use break to exit the loop if the user enters the correct username
– use exit() to stop the program running if the username is entered incorrectly three
times.

205
369825_9.6_Cam_LSC_SB_198-235.indd Page 206 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

4 Add code to your main program, below the sub-program, to call login( ). Save the
completed program as TimesTableGameV1.py.
5 Copy and complete the table below to develop a test plan that uses normal, extreme
and invalid data to check the different pathways through your sub-program. An
example test has been included to get you started.

Expected
Test number Data entered outcome Pass/fail
1 Correct username = Welcome to
feedback "Superstar" the game
Think back to Unit 9.1, when
given when
you were introduced to normal,
the correct
username is
extreme and invalid data. Ensure
entered that you test data that should
be accepted, data that should
2 be rejected and data that is
3 on the boundaries of what is
acceptable.
4

6 Apply your test plan to your program to make


sure that it works correctly.
7 Identify the different variables used in your program for the login system and their
data types, and explain why these are the most appropriate data types to use, by
completing the table below.

Variable name Data type Justification

KEYWORDS
prototype: initial product created for testing and reviewing, before a final
product is released
test plan: document that details the tests to be carried out when a program
is complete and whether or not they are successful

206
369825_9.6_Cam_LSC_SB_198-235.indd Page 207 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

String manipulation
Learn
When a user enters data into a system, they may use a number of different data types.
A reminder of the key data types is shown below.

Data type Explanation


String A combination of letters, numbers or symbols Remember: Python does not
Character A single letter, number or symbol
have a specific data type for an
individual character. A single
Integer A whole number, negative or positive character is simply stored as a
Real A number with decimal places, negative or positive string with a length of 1.
Boolean Two possible values: True or False

As you’ve explored in previous units, when developing programs you need to consider
how the user might enter data, as it might not always be as you expect. You have already
used casting to change the data type of an input, for example, using int to store input
data as an integer. Remember that you can also use string manipulation to ensure that
the data is input in the correct format. Here’s a recap.

Imagine that you are developing a game that requires the user to enter their answer to
a multiple-choice question as a letter: for example, A, B, C or D.

If the user entered ‘a’ rather than ‘A’, they would


be told that their answer is incorrect, as Think back to Unit 9.4.
Python treats ‘A’ and ‘a’ as different characters. ASCII assigns each character
that a computer can
One solution to this problem would be to edit represent a unique binary
the program code using a Boolean operator to code, and this includes upper
check for alternative inputs. and lowercase characters.

However, there are also a range of different string manipulation techniques that can be
used to return new values where the contents of a string have been altered.

207
369825_9.6_Cam_LSC_SB_198-235.indd Page 208 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

The upper() method converts all the characters of a string to uppercase.

When the program is run and the user enters ‘a’, it is changed to ‘A’.

The lower() method converts all the characters of a string to lowercase.

In both of the examples below, the alphabetical characters have been changed to
lowercase. The numbers are ignored and remain the same.

The capitalize() method converts the first character of a string to uppercase and
all the rest of the characters to lowercase.

Note that all the characters input by the user are stored as a single string.
Therefore, if there is more than one word separated by a space, only the very first
letter of the first word is in uppercase.

208
369825_9.6_Cam_LSC_SB_198-235.indd Page 209 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Another useful function that can be used with strings is len():

This tells you the number of characters in a string:

It can be used to check whether anything has been input, as the length of the string is 0 if
nothing is stored in it:

KEYWORDS
data type: classification applied to a data item specifying which type of data
that item represents, e.g. in a spreadsheet some of the data types available
include currency, text and number
cast: change the data type of a variable
string manipulation: process of changing the format of a variable/string to
allow it to be analysed

Practise
1 Open the file StringManipulation.py provided by your teacher.
a Add code where the comments are so that the program completes the following
string manipulation:
– ‘first’ is capitalised
– ‘middle’ is changed to uppercase
– ‘last’ is changed to lowercase.
b Test your program using the following inputs:
– first = sanya
– middle = ali
– last = ABBAS

209
369825_9.6_Cam_LSC_SB_198-235.indd Page 210 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

2 Open your file TimesTableGameV1.py from the previous section. You are going to use
iterative development processes to add further functionality to what you have created
previously.
a Edit the sub-program login() so that the program capitalises the username
entered by the user.
b Develop the sub-program further to add a check to make sure that a username has
been entered. To do this, you need to use a conditional statement to check the
length of the username the player has entered. If it has a length of 0, your program
should tell the player ‘You did not enter a username’.
c Save the updated program as TimesTableGameV2.py.
3 Test your code to make sure that the username entered by the player is capitalised,
and that a suitable message is output if no username has been entered.
4 Use the flowchart below to add a new sub-program age() to your times-table game to
check that the user is the correct age to play the game.

age()

INPUT age

No No OUTPUT
is age >= 7
is age < 7? "Sorry! You are
AND <= 10?
too old."

Yes Yes

OUTPUT OUTPUT
"You are the "Sorry! You are
correct age." too young."

Stop exit()

5 a If the player is too young or too old, the program should give appropriate feedback
and then use the function exit() to stop running.
b Save the program that you have developed as TimesTableGameV3.py.
6 Copy and complete the table on the next page and develop the test plan to check that
your new sub-program works correctly. Make use of normal, extreme and invalid test
data in your test plan. An example test has been included to get you started.

210
369825_9.6_Cam_LSC_SB_198-235.indd Page 211 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Test number Data entered Expected outcome Pass/fail


1 Correct feedback when the username = Welcome to the game.
age is between 7 and 10 "Superstar" You are the correct age.
age = 10
2
3
4

7 Get your partner to use your test plan to check that your code works as it should.

KEYWORD
conditional statement: completes a check to see whether set criteria is
either True or False

Tracing through the lines

Learn
When creating algorithms or writing programs, you should always test them thoroughly.
You are already used to doing this using a test plan.
As you explored in previous units, you can use trace tables alongside test plans to follow
each line of an algorithm or program through step by step.
l A test plan provides you with the data to be input and the expected outcome.
l Trace tables allow you to see the value of each variable as each line of code is executed
and can be used to identify any potential errors.
The program below uses two variables, ‘x’ and ‘y’. If ‘x’ is greater than or equal to ‘y’ then
it should add the contents of the two variables; otherwise, it should multiply them.

Remember: a trace table has headings for the line number and all the variables, as well as
a column for the output. You may also find it helpful to include a column heading for the
condition checks in an IF statement, to record the Boolean result.

211
369825_9.6_Cam_LSC_SB_198-235.indd Page 212 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Here is a trace table for the program on the previous page.

Line x y x >= y Output


1 20
2 15
3 True
4 300
7 Program complete

This example has helped to identify a logic error. The program has multiplied the two
values when ‘x’ is greater than ‘y’, when it should have added them.
Trace tables are extremely helpful when checking algorithms and programs that use
iteration as they can include a column to track the value of the loop variable.
Look at the pseudocode algorithm below.
1 value = 3
2 FOR number = 1 to 5
3 x = value * number
4 y = x * 2
5 IF y > 20 THEN
6 OUTPUT y
7 ENDIF
8 ENDFOR

Work through the trace table below to see how the values of the variables change for
each line of the algorithm.

Line Variable Variable Variable Variable Condition Output


value number x y y > 20
1 3
2 1
3 3
4 6
5 False
2 2
3 6
4 12
5 False
2 3
3 9
4 18
5 False

212
369825_9.6_Cam_LSC_SB_198-235.indd Page 213 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Line Variable Variable Variable Variable Condition Output


2 4
3 12
4 24
5 True
6 24
2 5
3 15
4 30
5 True
6 30

A simplified version of the trace table could show just the values at the end of each
iteration.

Line Variable Variable Variable Variable Condition Output


value number x y y > 20
6 3 1 3 6 False
Note that the ‘Variable’ and
6 2 6 12 False ‘Output’ columns do not always
6 3 9 18 False have to contain a value. It is
usual to enter a value only if it
6 4 12 24 True 24 has changed.
6 5 15 30 True 30

KEYWORDS
trace table: technique for predicting step by step what will happen as each
line of an algorithm or program is run, and to identify errors
execute: carry out the instructions described in a computer program
IF statement: in Python, this evaluates a condition which determines the
path of the program depending on whether the condition is true or false

213
369825_9.6_Cam_LSC_SB_198-235.indd Page 214 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Copy and complete the trace table for the program below:

Line x y z x >= y z>9 Output

2 Open the file TraceTablesActivity1.py provided by your teacher and run the program.
Do the outputs in your trace table match those from the program? Have you managed
to trace a Python program successfully to ensure that it is free from errors?
3 Copy and complete the trace table for the program below.

214
369825_9.6_Cam_LSC_SB_198-235.indd Page 215 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Line a b i Output

4 Open the file TraceTablesActivity2.py provided by your teacher and run the program.
Do the outputs in your trace table match those from the program?
5 Create trace tables for the following programs to demonstrate that you can follow
pseudocode algorithms that use loops.
a 1 num1 = 3
2 num2 = 2
3 total = 0
4 FOR x = 1 to 3
5 num1 = num1 * x
6 num2 = num2 * 2
7 total = num1 + num2
8 ENDFOR
9 OUTPUT total
b 1 x = 1
2 y = 1
3 z = 0
4 FOR x = 1 to 2
5 FOR y = 1 to 3
6 z = (x * y) * 3
7 OUTPUT z
8 ENDFOR
9 ENDFOR

215
369825_9.6_Cam_LSC_SB_198-235.indd Page 216 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

It’s all in the lists


Learn
When you want to store a single item of data in a program, you use a variable. A variable
is a named memory location that can store a value: for example, name = "Petra". The
contents of a variable can be changed at any point in a program.
If you wanted to store five names using variables, you would have to use five different
variables to store the names: for example,
name1 = "Petra"
name2 = "Adnan"
name3 = "Amir"
name4 = "Mira"
name5 = "Rayah"
Remember: an array is a data
This is fine if you have only a few different names to
structure that allows you to
store, but imagine you wanted to store 100 different store multiple pieces of data
names. It would not be very practical to have 100 under a single identifier.
different variables, each storing one name. Instead,
you can use a one-dimensional array: for example,
name1 = ["Petra", "Adnan", "Amir", "Mira", "Rayah"]

You can think of an array as a series of boxes, each of which contains one item of data.
These items of data can be indexed. This means that they can be accessed individually
using their index number, and the first item always has the index 0: for example,

name
0 1 2 3 4
Petra Adnan Amir Mira Rayah

If you wanted to print the name Amir from the array above, you would use the code
print(name[2]). The number in square brackets after the name of the array is the index
number or position where the element can be found.
A drawback of arrays is that they allow only data of the same data type to be stored.
name = ["Petra", "Adnan", "Amir", Allowed; all use the string data type
"Mira", "Rayah"]
topScores = ["Petra", 55, "Adnan", Not allowed; this a combination of string and integer
46, "Amir", 44] data types

Python uses data structures called lists and tuples to create arrays. These work in a
similar way to arrays, but they allow a mixture of different data types to be stored in them.
The difference between a list and a tuple is that the elements inside a list can be changed,
but the contents of a tuple cannot be changed.

216
369825_9.6_Cam_LSC_SB_198-235.indd Page 217 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

In Python, a list is created using square brackets: [ ]. Each item in the list is separated
from the next element by a comma.
Look at the program below. Can you work out what will be printed when the program is
run?

The program retrieves and prints elements from the list to create a sentence.

The data contained in a list can also be used to perform calculations. Look at the program
below. Can you work out what will be output when the program is run?

This program adds together 15 (index 0) and 12 (index 4) to give the answer 27.

In this list, there are no quotation marks. This is because the values are stored as integers
and not strings.

KEYWORDS
data item: piece of information that represents part of the data that makes
up a person, place or thing, e.g. some of the data items that represent a
person are their first name and second name
variable: named memory location that can store a value
one-dimensional array: series of items grouped together under one
identifier
index: numerical reference for a location of a piece of data stored in an array
list: data structure in Python that can store multiple items of data of mixed
data types under a single identifier; data items can be changed
tuple: data structure for storing multiple items of data in a single variable;
values cannot be changed

217
369825_9.6_Cam_LSC_SB_198-235.indd Page 218 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Copy and complete this paragraph about the purpose of a one-dimensional array by
filling in the blanks. Select from the words below.

When you want to store multiple items of data about the same thing, instead of
using lots of … you should use an …. In Python, this can be done using lists or ….
Lists allow you to … the data they contain; tuples … you from changing the data. To
retrieve the value 5 from the list points = [4,7,5,3,8], you would write the code ….

tuples variables array points[3]


change points[2] prevent

2 Open a new program file in Python, and create a program that does the following.
a Creates a list called 'countries', which stores the following countries: Belgium,
Andorra, Malta, Mali, Sri Lanka.
b Displays the countries in alphabetical order by accessing them from the array in
Python using the print command: for example,

c Save the program as CountriesList.py and test it to ensure that it produces the
output shown above.
3 Follow the pseudocode below and copy and complete the table to determine the
output from each calculation.
score = [25, 34, 15, 17, 20]
OUTPUT score[2] + score[3]
OUTPUT score[4] - score[2]
OUTPUT score[2] * score[4]
OUTPUT score[1] / score[3]
OUTPUT (score[0] + score[2]) / score[4]

Calculation Output
score[2] + score[3]
score[4] - score[2]
score[2] * score[4]
score[1] / score[3]
(score[0] + score[2]) / score[4]

218
369825_9.6_Cam_LSC_SB_198-235.indd Page 219 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

4 Open your file TimesTableGameV3.py (from the ‘String manipulation’ section). You are
now going to add a sub-program called character() to allow the user to choose their
character name.
a Choose the names for five characters and store them in a list with a suitable name.
b Use the print command to display each character name in turn.
c Once all five names have been displayed, ask
the player to enter their choice of character,
and store this in a variable. The number that the player
d Confirm the character they have chosen by enters as their choice will be one
printing the character’s name as part of a higher than the index number
sentence. you need to use to print the
character’s name.
e Return the character name to the main
program.
Here is an example of what the sub-program may look like when it is run.

5 Add code to the end of the main program, to call the sub-program character() and
assign the value that is returned to a variable called ‘charName’.
6 Save the updated program as TimesTableGameV4.py. Test your code to make sure
that it is working correctly. Improve your code further so that if the user enters a
number that is not between 1 and 5, the program will automatically assign them the
first character name.
7 Save the updated program as TimesTableGameV5.py. Test your program to make sure
that it is working correctly.
8 Make sure that your program meets all the requirements listed in task 4.

DID YOU KNOW?


The maximum number of values you can store in a list varies depending on the
computer you are using. This is because it is dependent on the amount of RAM in your
computer. This means that if you have a large list in Python, it may work correctly on
one computer but not on another.
Don’t worry too much, though; you would probably need over 500 million items in your
list even to get close to this being a problem!

219
369825_9.6_Cam_LSC_SB_198-235.indd Page 220 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Using iteration with lists


Learn
Lists are incredibly useful for storing multiple pieces of data without the need for lots of
variables. However, retrieving each item from a list individually can require a lot of lines
of code:

If this list contained 100 scores, using this approach would require a separate line of code
to print each piece of data. Instead, it is possible to use iteration to simplify and shorten
the code:

Both of these examples give exactly the same output:

The example using iteration would always use just four lines of code, even if the program
displayed the top 100 scores.
Look at the second program in more detail.

This creates a list called ‘highScores’ that


contains five values
This displays the text between the quotation
marks using the print function
This is a loop that repeats five times; ‘x’ is
the loop variable
x+1 displays the number of the high score;
‘x’ has a value of 0 to begin with, so we need
to add 1 to display the correct number
highScores[x] retrieves the value from
the list with the index ‘x’

220
369825_9.6_Cam_LSC_SB_198-235.indd Page 221 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Iteration can be used to handle the data in lists for a range of different purposes. The
program below uses iteration to add together all the scores in the list.

When the program is run, it gives the following output.

The trace table below shows how this is achieved.

Line Variable Variable output


x total
2 0
4 0 7
4 1 13
4 2 22
4 3 32
4 4 36
KEYWORD
4 5 41
for loop: the Python or
4 6 47 MicroPython loop for a
count-controlled loop
5 47

Of course, the number of items in a list may vary, which can cause problems when using
a for loop that repeats a set number of times. To overcome this problem, you can use the
len() function to set the number of times the loop needs to run.
In the program below, the len() function is used in line 3 to find the number of items in
the list, and the value is stored in the variable ‘length’. In line 4, ‘length’ replaces a fixed
value for the upper boundary of the loop. If the number of items in the list increases or
decreases, then the program adjusts automatically to run the loop the correct number of
times: for example,

When the program is run, it gives the following output.

221
369825_9.6_Cam_LSC_SB_198-235.indd Page 222 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Practise
1 Copy and complete the trace table to check the algorithm below for any bugs and
predict the outcomes. The first three lines have been completed for you.
1 scores = [7, 9, 14, 10, 3, 6, 9, 1]
2 total = 0
3 bonus = 0
4 FOR x = 0 to 7
5 total = total + scores [x]
6 IF scores [x] > 8 THEN
7 bonus = bonus + 2
8 ELSE
9 bonus = bonus + 1
10 ENDIF
11 ENDFOR
12 finalScore = total + bonus
13 OUTPUT finalScore

Line Variable Variable Variable Variable Output


x total bonus finalScore
2 0
3 0
9 0 7 1

2 Look at the pseudocode below.


1 words = [Good morning, Goodbye, you, today?, how, are, Good
afternoon]
2 day = INPUT
3 IF day == "AM" THEN
4 OUTPUT words[0], words[4], words[2], words[5], words[3], words[1]
5 ELSEIF day == "PM" THEN
6 OUTPUT words[6], words[4], words[5], words[2], words[3], words[1]
7 ELSE
8 OUTPUT "You haven't entered AM or PM.", words[1]
9 ENDIF

222
369825_9.6_Cam_LSC_SB_198-235.indd Page 223 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

a Copy and complete this table to predict the output if the


following values are entered.

Day Output
AM
AP
PM

b There is an error in the code on line 4, resulting in the


output being displayed incorrectly. Rewrite this line of code
so that the program works correctly.
3 Open your file TimesTableGameV5.py (from the previous
section).
a Improve the code in the sub-program character() using
iterative development processes so that it uses a count-
controlled loop to retrieve and display all the names from
the array, rather than a series of print commands.
b Save the updated program as TimesTableGameV6.py.
c Test your program to make sure that it still works correctly.
4 Add a new sub-program called timesTable() that asks the
player which times table they would like to practise. Return
the value to the main program.
5 Add code to the end of the main program to call the sub-
program timesTable() and assign the value that is returned
to a variable called ‘table’.
6 Save the updated program as TimesTableGameV7.py. Test
your code to make sure that it is working correctly.

Computational thinking – algorithms


During this unit, you have been exploring lists in Python. As part
of this, you have created programs that retrieve information KEYWORDS
from lists. When dealing with lists of values or numbers, there linear search:
are different ways in which you can search through them to see sequential method of
searching a list from
whether they contain a specific value.
start to end, checking
Two common methods of searching lists are the linear search and each element in turn
binary search. A linear search simply starts at the first value in the binary search:
list and checks each element in turn. It continues doing this until it divide-and-conquer
algorithm that splits
finds the value that is being looked for, or until it reaches the end of
an array in half each
the list, in which case it can output that the value is not in the list. In iteration, checking
a linear search, the list does not have to be in any particular order. the middle value to
determine whether
The other method is called a binary search. A key difference it is higher or lower
between a linear search and a binary search is that the list must or it has found the
be in numerical or alphabetical order to perform a binary search. required value

223
369825_9.6_Cam_LSC_SB_198-235.indd Page 224 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Here is an example of a binary search to see whether the number


9 is in the list below.

Index 0 1 2 3 4 5 6 7 8 9
Value 2 6 9 12 16 18 20 23 45 99

First, you need to find the middle value in the list. If there are an
even number of elements in the list then there isn’t a true middle
value, so it is usual to take the value to the left of the mid-point.
In this example, this would be index 4 with a value of 16.
Next you need to see whether the middle value is the one being
searched for. If it is, then the algorithm finishes. However, if it
is not, then the bottom half of the list plus the middle value is
discarded if the middle value is lower than the one being looked
for, or the top half of the list plus the middle value is discarded if
the middle value is larger than the one being looked for.
In this example, 16 is larger than 9, so 16 and all the values to the
right (that are higher than the target number) are discarded. The
remaining numbers form a new list:

Index 0 1 2 3
Value 2 6 9 12

The process is then repeated. This time, the middle value is 6.


This is not the value being searched for and is smaller than the
target value, so 6 and the numbers below it are discarded. This
leaves two values that create a new list:

Index 0 1
Value 9 12

This time the middle value is 9. This is the number being


searched for, so the search is complete.
A worst-case scenario for a linear search is that the value you are
looking for is the last item in the list. In a binary search, you are
discarding half of the values each time and therefore the search
is usually much quicker.
1 Perform a binary search on the following values to find the
number 42.

6 9 15 18 20 24 27 33 37 40 42 49

2 Perform a binary search on the following list to find the string


‘Blue’.

Black Blue Green Orange Pink Purple Red White Yellow

3 Explain the steps a binary search follows to look for a number


in a sorted list.

224
369825_9.6_Cam_LSC_SB_198-235.indd Page 225 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Identifying errors and debugging


Learn
Being able to identify errors and correct them is a fundamental skill in programming. To
recap, there are two main ways in which you can identify errors and debug them.

l The first is through trial and error. This requires you to write some code, run your
program and see whether it works. If it doesn’t work, then you need to make
changes to your code and try to run it again until it does what you want it to do.
l Another method of identifying errors is through using a test plan. You should
develop a test plan before you write your program. It should clearly identify what
tests you are going to carry out when you have developed the program and what
the program should do. When you have finished developing the program, you
should carry out these tests to find any potential issues.

You have already written and used test plans, and these have usually focused on
making sure that the program works and produces the outputs that you are expecting.
A thorough test plan includes three different types of data. Can you remember what
these are?
l Normal
l Extreme
l Invalid

When you try to run and test your program, there are three main types of errors that you
may come across. These are:
l syntax errors
l logic errors
l runtime errors.

Here’s a reminder of these errors.


Syntax errors
A syntax error is something that breaks the grammatical rules of the programming
language. This can include misspelling a keyword or variable, missing brackets or speech
marks, incorrect indentation or using assignment incorrectly. Syntax errors stop a
program from running.
Common syntax errors include the following.

Error Example Explanation


Misspelling a keyword On line 1, input is spelled
incorrectly

Missing brackets On line 1, there is a bracket


missing from the end of the
line

225
369825_9.6_Cam_LSC_SB_198-235.indd Page 226 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Error Example Explanation


Missing quotation On line 2, Hello should be
marks in quotation marks as it is a
string
Incorrect indentation On line 3, the print
of code statement needs to be
indented

Logic errors
A logic error is an error in the algorithm that produces an incorrect or unexpected output.
The program will still run, but the desired output is not produced. Logic errors are harder
to spot because it is not always obvious that there is an issue with the program.
Common logic errors include the following.

Error Example Explanation


Using Boolean On line 2, or has been
operators used instead of and; this
incorrectly will give the output ‘You
are a teenager’ for any
age that is entered

Incorrect use On line 4, the average is


of BIDMAS in calculated incorrectly as
calculations num3 will be divided by 3
before being added to the
other variables; num1 +
num2 + num3 needs to
be inside brackets so that
this part of the calculation
is completed first
Using logical On line 2, the incorrect
operators operators have been used;
incorrectly it should be age > 12
and age < 20

Runtime errors
A runtime error occurs when Python understands the code but runs into a problem when
it tries to execute it. In English, a runtime error would be something like the sentence
‘Jump on the ceiling’. It makes sense but it is something that cannot be completed. The
name runtime error comes from how it is encountered once the program is running.

226
369825_9.6_Cam_LSC_SB_198-235.indd Page 227 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Common runtime errors include the following.

Error Example Explanation


Trying to use a The program would give a
variable that doesn’t NameError, as myAge and
exist or has been myage are not the same
misspelled
Dividing by zero A ZeroDivisionError would be
produced, as dividing by zero
makes no sense in maths

Trying to access items The program would give an


in a list that do not index error as there is no item
exist at ‘index 3’ in this list

KEYWORDS
normal test data: data of the correct type that should be accepted by a program
extreme test data: acceptable input but at the ends of the possible input range
invalid test data: data that should be rejected by a program
syntax error: error in program code that stops the program from running
logic error: error that allows a program to run but not output what is expected
runtime error: error that occurs while a program is running; the instructions cannot be completed

Practise
1 Identify the syntax errors in the program below. For each error, say which line it is on,
describe the error and write a corrected version of the program code.

2 The algorithm below should ask the user to enter three numbers and then calculate
the average of the three numbers. If the average is more than 50, it should output
‘Well done’; otherwise, it should output ‘Try again’. Identify the logic errors in the code
that prevent the algorithm from working correctly. For each error, say which line the
error is on and how to correct it.
1 total = 0
2 FOR x = 0 to 5
3 number = INPUT
4 total = total * number
5 ENDFOR

227
369825_9.6_Cam_LSC_SB_198-235.indd Page 228 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

6 average = total / 3
7 IF average < 50 THEN
8 OUTPUT "Well done"
9 ELSE
10 OUTPUT "Try agin"
9 ENDIF
3 Open the file RuntimeErrorsProgram.py provided by your teacher. This program
should add together all the numbers in the array and multiply them by the number
entered by the user. Correct the runtime errors in the program.
4 Develop a test plan for the ‘age’ sub-program of your game. Open the latest version
of your game (this should be TimesTableGameV7.py). Make sure that you include all
types of test data in your test plan.

Test number Data entered Expected outcome Actual outcome


1
2
3
4

Go further
Previously, you have looked at how you can retrieve data from lists in Python using one-
dimensional arrays. There are a number of ways in which the contents of an array can be
altered, including adding data, changing data and removing data.
Here are some examples of ways in which the contents of a list can be altered.

List method Example What it does


append() append() adds an item at the
end of a list

insert() insert() adds an item to a list


at a specific index position; this
alters the index numbers of all
the items that follow it

Changing The value of an item in a list can


the contents be changed by assigning a new
using ‘index’ value to the index position; in this
example, ‘banana’ is overwritten
by ‘orange’ at index 1

228
369825_9.6_Cam_LSC_SB_198-235.indd Page 229 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

List method Example What it does


remove() remove() removes the first
occurrence of an item with a
specific value

pop() pop() can be used to remove an


item using its index

1 Open the file Altering Lists.py provided by your teacher. This program stores in a list
the names of the five countries with the highest population and displays them in order.

2 The program needs editing to display the ten countries with the highest population. Update
the code that uses a one-dimensional array and use .append() to add Brazil, Bangladesh,
Russia, Mexico and Japan to the list. The finished program should look like this.

3 There has been an error in the order of countries. Insert Pakistan between Indonesia
and Nigeria. The finished program should look like this.

4 Now there are eleven countries in the list, the final country, Japan, needs to be
removed from the list. Update your code to reflect this.

229
369825_9.6_Cam_LSC_SB_198-235.indd Page 230 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

Challenge yourself
Now that you know how to alter the contents of a list, you are going to develop your
game further so that the player can add a character of their choice to the list or alter the
other characters that are available.
Your sub-program will still need to display the original list of characters, but will then
need to give the player some options to choose from.
You will need to edit the sub-program character() so that the program allows the player
to:
l add a character to the list
l change a character that is stored in the list for a character of their choice
l remove a character from the list
l choose a character from the existing list.

The updated list should be displayed to the user before allowing them to make their final
choice.
Use the pseudocode below as a guide for the options that your sub-program will need to
include.
OUTPUT "What would you like to do?"
OUTPUT "1. Add a character?"
OUTPUT "2. Change a character"
OUTPUT "3. Delete a character"
OUTPUT "4. Choose a character from the existing list"
INPUT option
IF option == 1 THEN …

1 Add the required code to the latest version of your times-table game program
from previous sections (this should be TimesTableGameV7.py). Ensure that your
developments complete each of the operations outlined.
2 Save your edited program as TimesTableGameV7cy.py and test it to make sure that it
works correctly.

230
369825_9.6_Cam_LSC_SB_198-235.indd Page 231 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Final project
Look back at the start of this unit to remind yourself of the Scenario. You have already
created several parts of the game, but you now need to develop the code to ask the
questions and keep a score.

Criteria for this part of the game are as follows.


l The game must ask the player five multiplication questions that are phrased as
sentences. For example, instead of 2 × 5, it would ask questions such as ‘In the
cave, you see 2 trunks each containing 5 coins. How many coins do you have?’
l Each question will include the name of a room, the name of a container and
the name of something that is inside the container. These items will need to be
stored in three lists.
l The player will get two attempts to answer each question. If they get it right first
time, they will receive 2 points. If they get it right second time, they will receive
1 point. Otherwise, they will receive 0 points. After the five questions have been
asked, they will be told how well they have done, including how many correct
answers they got and how many were right at the first attempt.

Complete the following tasks.


Part 1
1 Open your file TimesTableGameV7.py or TimesTableGameV7cy.py if you completed
the ‘Challenge yourself’ tasks.
a Import the ‘random’ library at the top of the program, as you have previously
learned, by adding the code import random on line 1.
b Define a new sub-program called question() and pass ‘table’ into it as a
parameter by adding table into the parentheses: question(table).
c Create three lists, called ‘rooms’, ‘containers’ and ‘items’. Each list should contain
at least five different items.
2 The code random.choice() will retrieve an item randomly from a list:

a Use random.choice() to select an item from each list and store these in separate
variables.
b Generate a random number between 2 and 12 and store it in a variable called
‘number’.
3 Use the pseudocode on the next page to help you to write the program code to
display the question and get the player’s answer. The letters ‘V’, ‘W’, ‘X’, ‘Y’ and ‘Z’
have been used to indicate where you should insert certain variables into the output.

231
369825_9.6_Cam_LSC_SB_198-235.indd Page 232 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

V = table
W = random number (2,12)
X = random choice(rooms)
Y = random choice(containers)
Z = random choice(items)

OUTPUT "In the X you see V Y containing W Z."


OUTPUT "How many Z do you have?"
answer = INPUT

4 Use the flowchart on


Start
the right to help you to
write the program code
to check whether the
points = 0
answer is correct and
award the appropriate
number of points. If the
answer is not correct
INPUT answer
the first time, then the
program will need to
give the user a second
chance to answer the
question. The number is answer == Yes OUTPUT
points = 2
of points scored should V*W "That’s correct"
be returned to the main
program. No

OUTPUT
"Try again"

INPUT answer

is answer == Yes OUTPUT


points = 1
V*W "That’s correct"

No

OUTPUT
"No. The answer
is V * W"

RETURN points

232
369825_9.6_Cam_LSC_SB_198-235.indd Page 233 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

5 a Create two variables in the main program called ‘score’ and ‘first’. They should
both have a value of 0.
b Use the pseudocode below to help you to call the function question(), store the
value that is returned and update the values of ‘score’ and ‘first’. You will need to
use a for loop to make this section of code run five times so that five questions are
asked.
FOR i = 1 to 5
points = SUBROUTINE question(table)
score = score + points
IF points == 2:
first = first + 1
ENDIF
ENDFOR

c Save your program as TimesTableGameV8.py.


d Test your program with appropriate data to check that it is working, before
progressing to the next stage.
Part 2
1 The final stage of the game should tell the player how well they have done and give
them some feedback.

l First, address the player by name and tell them how many points they scored
and how many questions they answered correctly at the first attempt.
l Then give them some feedback based on the score that they achieved.
l Include the number of the times table that they were practising. This is shown
as V in the examples below.
a 8 or more points: ‘Well done! You know your V times table.’
b 5 or more points: ‘A good effort. You know some of your V times table.’
c Less than 5 points: ‘You need to practise your V times table.’
Here is an example of how this might look when the program is run:

a Create a flowchart algorithm for the ‘feedback’ sub-program. It will need to


use ‘charName’, ‘score’, ‘first’ and ‘table’ as parameters passed in from the main
program.
b Create a new sub-program called feedback() that takes in the four parameters
‘charName’, ‘score’, ‘first’, ‘table’.
c Use the flowchart algorithm you have just made to help you to write the code for
the feedback() sub-program.
d Save your finished program as TimesTableGameV9.py.

233
369825_9.6_Cam_LSC_SB_198-235.indd Page 234 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

2 Copy the table below and create a test plan for the ‘feedback’ sub-program. Include
normal, extreme and invalid test data.

Test number Data entered Expected outcome Pass/fail


1
2
3
4

3 Copy and complete the table below, listing the variables used throughout your whole
program, their data types and a justification for the data type you have chosen.

Variable name Data type Justification

4 Copy and complete the trace table for the following part of the algorithm if the
points returned from the sub-routine are 2, 1, 0, 1, 2.
1 FOR i = 1 to 5
2 points = SUBROUTINE question(table)
3 score = score + points
4 IF points == 2:
5 first = first + 1
6 ENDIF
7 ENDFOR

Line Variable Variable Variable Variable


i points score first

234
369825_9.6_Cam_LSC_SB_198-235.indd Page 235 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Unit 9.6 An array of skills

Evaluation
1 Swap programs with your partner and play each other’s games. Comment on the
following.
a Does their game cover all the requirements?
b Is their game easy to use?
c Are the messages easy to understand?
d Does the game calculate the score correctly depending on how many attempts it
takes to get the correct answer?
2 Now open your own program and look at the code. Reflect on what you could improve
in your game. Things you might want to think about include:
– Is it easy to get full marks? How could you make the game easier/harder?
– How could you develop the game further? Could you add additional levels? What
would they look like? How could you use lists in your programming to do this?
3 Based on these evaluations, make a list of recommendations to improve your game.
4 Attempt to make the improvements to your game.

What can you do?

Read and review what you can do.


4 I can identify and explain the purpose of a one-dimensional array.
4 I can develop a Python program with count-controlled loops.
4 I can access data from an array using Python.
4 I can develop Python programs using string manipulation, including length,
uppercase and lowercase.
4 I can use iterative development on Python prototypes to create solutions to
problems.
4 I can develop and apply test plans using test data that is normal, extreme and
invalid.
4 I can identify and describe a range of errors, including syntax, logic and runtime
errors.
4 I can use a trace table to debug a Python program.
4 I can follow, understand, edit and correct algorithms that are presented as
pseudocode.
4 I can use a sub-routine in flowcharts or pseudocode.
4 I can explain and use iteration statements with count-controlled loops in either
pseudocode or flowcharts.
4 I can describe how a binary search is carried out, and perform a binary search on a
given list.
4 I can predict the outcome of algorithms that use iteration.

235
369825_Glo_Cam_LSC_SB_236-241.indd Page 236 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Glossary
5Vs: the terms used to describe the concept of Big Data: Big Data analytics: the analysis of sets of data known
volume, velocity, variety, value, veracity as Big Data
accelerometer: detects a change in direction of a device binary data: data that is represented as a 1 or a 0
accessibility: how successfully a new product or piece of binary digit: 0 or 1; the smallest unit of binary data
software can be used by anyone represented on a digital device
accumulator (ACC): holds the results of processing binary search: divide-and-conquer algorithm that splits
carried out by the arithmetic logic unit an array in half each iteration, checking the middle
active internet connection: where a device has a value to determine whether it is higher or lower or it has
working connection to the internet found the required value
administrator: account with top-level access, with the biometric security: security method that identifies
ability to change settings or add and remove users from people using a physical attribute (e.g. a fingerprint) or a
a network behaviour (e.g. a hand gesture)
algorithm: step-by-step instructions to solve a particular bit: short for ‘binary digit’: 0 or 1
problem bit depth: the number of bits used to store a single
analogue: continually varying signal, e.g. a sound signal sound sample
analogue-to-digital converter (ADC): converts block: string of data (0s and 1s)
analogue signals, e.g. the human voice, to digital signals block-based program: individual code blocks connected
applications software: software designed to do a together to create a program
particular task, e.g. a word processor, spreadsheet, web Boolean expression: expression that contains
browser, mobile-phone app conditional operators; symbols, e.g. >, < and =, used to
arithmetic logic unit (ALU): carries out the calculations carry out comparisons between two values
needed during the execution of a program brute-force attack: type of unauthorised access to a
array: data structure in a program that can store more computer system that uses a large dictionary to try
than one item of data of the same data type under a multiple password combinations until it is successful
single identifier; data items can be changed bus topology: network in which all devices are
artificial intelligence (AI): ability of a computer system connected together via a main cable running down the
to learn and develop its own programming from the centre of the network
experiences it encounters byte: eight bits of data, e.g. 01010011
assembler: translates assembly-language instructions camelCase: all lowercase, and from the second word the
into machine code and creates one line of machine code first letter is capitalised
for each assembly-language instruction cast: change the data type of a variable
assembly language: set of codes or symbols that Central Processing Unit (CPU): the part of the
represent each instruction, rather than a group of 1s computer that carries out program instructions,
and 0s sometimes known simply as the processor
attribute: heading for organising data in a relational character: single letter, digit or symbol
database
chatbot: software application that uses text to ask
authenticate: confirm a user’s details to ensure that questions to help a user
they should be allowed access to a system
cloud computing: using servers on the internet for
backup: copying files to another location in case the services
original is lost or damaged
colliding: when data ‘bumps into’ other data, which
Big Data: datasets that are too large or complex for often causes errors or lost data
traditional data-processing applications, e.g. databases
command line: way of using an operating system that is
or spreadsheets, to process
navigated by typing commands

236
369825_Glo_Cam_LSC_SB_236-241.indd Page 237 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Glossary

compiler: translates an entire computer program into data type: classification applied to a data item
machine code and creates a file containing machine specifying which type of data that item represents,
code for the entire program e.g. in a spreadsheet some of the data types available
complex query: where more than one criterion can be include currency, text and number
used to search a database, or a query can be used to database: application that organises data for storing,
combine data from more than one table, or calculations processing and accessing electronically
can be performed using the data in a query dataset: collection of related information that a
concatenation: joining two strings together computer can manipulate
conditional operator: symbol, e.g. >, < and =, used to decode: work out what an instruction means/what it is
carry out comparisons between two values telling the Central Processing Unit to do
conditional statement: completes a check to see defragmentation: reorganising files stored on a hard
whether set criteria is either True or False drive to ensure that all parts of the same file are located
control unit (CU): issues commands to the other one after the other on the drive
hardware components to help ensure programs are device driver: software program that operates a
carried out correctly hardware device connected to a computer
convert: change from one unit to another, e.g. storage digitise: convert into digital format, i.e. into 1s and 0s
units (e.g. bits/bytes/kilobytes) domain name: part of a URL that specifies the location
count-controlled loop: set of instructions repeated a set on the internet, e.g. google.com
number of times dry run: process of working through an algorithm
cookies: small pieces of data, collected from websites manually to trace the values of variables
and stored as text by web browsers efficient: the efficiency of a program can be measured
COUNT function: checks all the cells in a specified by how quickly it runs
range in a spreadsheet and outputs how many contain a emerging technologies: new technologies that can be
numeric value incorporated into a design to improve how the product
counter variable: variable that stores the number of operates
times an iteration has iterated encryption: converting information into a scrambled
criteria: set of rules that must be met form, so that it cannot be understood if it is intercepted
crocodile clips: cable for creating a temporary electrical entity: person, place or object represented in a table in a
connection between devices relational database
current instruction register (CIR): stores the address of entity relationship diagram (ERD): diagram that
the instruction the Central Processing Unit is currently illustrates the relationships between two entities in a
executing relational database
cyber-attack: attempt to gain unauthorised access to a ergonomics: how a product or piece of software is
network, to damage or destroy a computer system designed or arranged so that it can be used efficiently
data: raw facts and figures evaluation: checking the suitability of a solution to a
data dictionary: table that represents the structure of problem
a database table at the design stage of developing a evolving: changing and improving
database; often contains details, e.g. data type, field length execute: carry out the instructions described in a
and details about validation checks applied to data items computer program
data-entry error: error that occurs when data is being extreme test data: acceptable input but at the ends of
entered into a database the possible input range
data item: piece of information that represents part facial recognition: system that matches a real-time
of the data that makes up a person, place or thing, e.g. image of a human face with a database of saved facial
some of the data items that represent a person are their representations to allow a user access to a digital device
first name and second name
feedback: comments made to help improve a product
data packet: small unit of data that is packaged to be
fetch: collect an instruction from another location
sent across a network
file server: server that stores users’ files and enables
data redundancy: when data is unnecessarily repeated
them to be shared on a network
in a database

237
369825_Glo_Cam_LSC_SB_236-241.indd Page 238 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

fingerprint recognition: system that matches a real- Hypertext Transfer Protocol Secure (HTTPS): set of
time image of a human fingerprint with a database of rules for communicating with web servers, with added
saved fingerprint representations to allow a user access encryption to improve security
to a digital device IF statement: in Python, this evaluates a condition
firewall: restricts the network traffic entering and which determines the path of the program depending
exiting a network, to ensure that it is safe on whether the condition is true or false
fit for purpose: something that is well designed for its incremented: when the value of a variable is increased
purpose by 1
flat-file database: database that stores all data items index: numerical reference for a location of a piece of
using one table data stored in an array
float: decimal number industrial revolution: rapid change in how society works
flowchart: visual representation of an algorithm following the introduction of new developments, e.g.
machines, computers, robots, AI, machine learning
for loop: the Python or MicroPython loop for a count-
controlled loop Industry 4.0: refers to how industry is combining
electronics with new technologies, e.g. machine learning,
foreign key: when the primary key from one table
artificial intelligence, robotics and green energy
appears in another table to establish a link between two
entities input mask: control added to a field in a database table
to control the format of data being added
fragmentation: situation that occurs when pieces of
files are scattered across the surface of a hard disc when instruction set: all the instructions in machine code that
the operating system is storing the file a Central Processing Unit can execute
function: sub-program that can exist as part of a bigger integer: whole number
program integrated development environment (IDE): software
general-purpose input output (GPIO): pins at the that includes all the tools needed to develop a program
bottom of the micro:bit that allow additional inputs and in a particular language
outputs to be added through crocodile clips interference: when electronic signals disrupt data
Global Positioning System (GPS): satellite-based transmissions
system that keeps track of users’ physical locations and Internet Service Provider (ISP): company that provides
helps with navigation users access to the internet, and is often responsible for
graphical user interface (GUI): way of using software the network equipment that connects LANs to WANs
that is navigated by pointing and clicking on graphics on interpreter: translates each line of high-level language
a screen code into machine code
hacker: somebody who tries to gain unauthorised access invalid test data: data that should be rejected by a
to a computer system or network program
hard disc drive: removable disc in computers for storing IP address: unique number assigned to a computer on a
large amounts of data, typically measured in gigabytes network
or terabytes iterate/iterative/iteration: repeat/repeated/repetition
hardware: physical parts of a computer that you can linear search: sequential method of searching a list
touch and see, e.g. the processor, storage devices, input from start to end, checking each element in turn
devices, output devices
list: data structure in Python that can store multiple
hertz (Hz): unit of measurement of how many sound items of data of mixed data types under a single
samples are taken in 1 second identifier; data items can be changed
high bandwidth: connection that can send and receive Local Area Network (LAN): type of network where
a large amount of data per second devices communicate over a small geographical area,
high-level language (HLL): programming language that e.g. a single building
uses commands and terms that are linked to the words logic circuit: combination of logic gates for solving a
or symbols a human would use when carrying out the problem in a digital device
same task
logic error: error that allows a program to run but not
Hypertext Transfer Protocol (HTTP): set of rules for output what is expected
communicating with web servers

238
369825_Glo_Cam_LSC_SB_236-241.indd Page 239 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Glossary

login system: method of accessing different systems programmed MAC address so that it can be identified
using a username and/or password on the network
loop variable: variable that counts the number of times network operating system (NOS): computer
code has been repeated in a count-controlled loop operating system that supports networks, often
low-level language (LLL): programming language including additional administrator software and
that uses commands that are similar to the type of monitoring tools
instructions the processor understands network switch: switch that connects devices together
MAC address: number programmed into a network to form a wired network
interface card that identifies each device on a network network topology: diagram that shows how devices in
machine code: combination of 1s and 0s that represent a network are connected to one another, and shows the
each instruction in the instruction set of a digital device network hardware
machine learning: ability of a computer system to learn network traffic: amount of data travelling through a
over time network, split into small parts for transmission
main memory: another name for RAM, which is used to normal test data: data of the correct type that should
store the programs and data the Central Processing Unit be accepted by a program
is currently using one-dimensional array: series of items grouped
many-to-many relationship: a primary key can exist together under one identifier
many times as a primary key on one table in a relational one-to-many relationship: a primary key can exist once
database and many times as a foreign key to link a as a primary key on one table in a relational database
second table in the relational database and many times as a foreign key to link a second table in
MAX function: returns the highest value in a specified the relational database
range of cells in a spreadsheet one-to-one relationship: a primary key can exist once
memory address register (MAR): holds the address of as a primary key on one table in a relational database
the memory location being accessed, either to read data and once as a foreign key to link a second table in the
from or write data to relational database
memory data register (MDR): any data or instructions online storage services: using file storage servers on the
that pass into or out of main memory must pass internet to store files
through the MDR operating system: software that manages all the
meteorology: study of climate and the weather computer hardware and software; it also acts as an
interface between computer hardware components
microprocessor: device that has one circuit but the
and the user, and provides a platform where
input, process and output functions of a computer
applications can run
MicroPython: programming language used on the
parameter: value that is passed into a function to be
micro:bit
used as part of a sub-program
MIN function: returns the lowest value in a specified
parameter query: query where the end user provides
range of cells in a spreadsheet
the search criteria
multiple-criteria query: query that uses more than one
parity bit: bit added to a byte to make the total number
criterion to select data items from a database
of 1 bits either even or odd
multi-table query: query that uses data from more than
parity byte: byte added to a block of data to check
one data table
whether the data is valid or invalid
naming convention: the way a variable or array is
parity-checking: type of error check that ensures data
named in programming
has been transmitted correctly
nesting: one programming construct, e.g. selection,
password: code made up of numbers or numbers and
occurring inside another construct, e.g. a count-controlled
letters and other characters (depending on the device),
loop
which allows a user access to a digital device
network: collection of computing devices connected to
Personal Area Network (PAN): type of network where
each other, either by wires or wirelessly
devices communicate over a small area of no more than
network interface card (NIC): every device that 10 metres, usually connecting devices a person wears to
connects to a network includes a NIC, which has a pre- a smartphone or computer

239
369825_Glo_Cam_LSC_SB_236-241.indd Page 240 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

personal identification number (PIN): sometimes relationship: feature in database applications for linking
called a PIN number or PIN code; a numerical passcode tables together
that allows a user access to a digital device remotely: connecting to a network from another
physical computing device: device that can be location via an internet connection
programmed using block or text-based programming report: feature in MS Access for displaying data in a
languages user-friendly format
plaintext: text that has not been encrypted and can be ring topology: network in which all devices are
read if it is intercepted connected together to form a ring
platform: hardware and operating system that runs an router: hardware device that connects networks
application together
plug-and-play device: device that is detected rule-based chatbot: chatbot with a set of questions
automatically and set up correctly for use by the built in that it asks and the user answers
operating system; no human intervention is needed
runtime error: error that occurs while a program is
primary key: field in a database table that provides a running; the instructions cannot be completed
unique identifier for a record/entity
sample rate: number of sound samples taken each
process: carrying out an operation on data, e.g. querying second
a database or doing a calculation using data in a
sampling: taking samples of a sound wave at fixed
spreadsheet
intervals
processor: electronic circuitry that executes the
scalability: capacity to make something larger, e.g. a
instructions described in a computer program; often
network enlarged with more devices
called the central processor or central processing unit
search criterion: data item used for comparison when
program: instructions that tell a computer system how
carrying out a search
to complete a task
security software: any type of software that secures
program counter (PC): stores the address of the next
and protects a digital device
instruction waiting to be executed (carried out) by the
Central Processing Unit selection: choice to be added to a program using if…
elif… else and the next instruction executed in the
protocol: agreed set of rules that computers follow to
program is decided by the outcome of a condition
communicate with each other over a network
sequence: order that program code needs to be in to
prototype: initial product created for testing and
work correctly
reviewing, before a final product is released
server: usually a powerful computer that offers a
pseudocode: textual representation of an algorithm
range of services to a network, e.g. file storage, user
query: tool that allows users to search for data that management, printer sharing, email access or web
meets specific rules or criteria servers
Query by Example (QBE): interface that allows users to simple query: where only a single search criterion is
select fields and criteria for use in a query in a database used to select data items from a database
application
snake_case: all lowercase, and spaces are replaced with
radio frequency identification (RFID) tags: technology underscores ( _ )
that uses radio signals to send data to another device
social-media application: web-based software that
Random Access Memory (RAM): memory used to allows users to share ideas, information and thoughts in
store programs and data currently being used by the an online community
processor
software: program or set of instructions that tell a
random value: randomly generated number in a computer what to do to complete a task; aspects of a
program that can be set within a range device you cannot touch
real: also known as a float; a decimal number spreadsheet: application that uses rows and columns to
register: location in main memory that temporarily organise data and carry out calculations using that data
stores data about memory locations, instructions and spreadsheet model: spreadsheet containing data that
data used during the execution of an instruction represents a real-life scenario
relational database: database that stores data using star topology: network in which each device is
two or more linked tables connected separately to a central switch

240
369825_Glo_Cam_LSC_SB_236-241.indd Page 241 06/03/23 9:54 AM A4902 /142/HO02737/work/indd

Glossary

storage units: number of bits used to store a data item tuple: data structure for storing multiple items of data in
in a digital device a single variable; values cannot be changed
string: sequence of characters that can be text, numbers two-dimensional parity check: check for finding where
or symbols; quotation marks around the characters an error exists within a parity check
define it as a string two-factor authentication: method of signing into a
string manipulation: process of changing the format of system that requires two types of authentication (e.g. a
a variable/string to allow it to be analysed password and a one-time SMS message code)
Structured Query Language (SQL): specialised user experience: how intuitive the product is based on
language for accessing data in relational databases the user’s previous experience with digital products or
sub-program: small program that can be called from the applications
main program to run at any time user management: adding or removing users to control
sub-routine: standalone section of code that can be access to a network
called from the main program user requirements: tasks a user expects of an application
sustainably: when a network is built in a way that it is utilities software: software that helps maintain the
easy to maintain in the future smooth functioning of a digital device by helping the
syntax: specific rules used in a programming language operating system manage tasks and resources
syntax error: error in program code that stops the validation: automatic checks applied to individual fields
program from running in a database table to help reduce the chance of error
when adding data to the table
systems software: software that helps a user run a
computer value: how useful data is to an organisation
table: set of facts or figures that are set out in a column variable: named memory location that can store a value
and row structure variety: the range of data formats and data types
terminator: ending to a network cable that absorbs the collected
signal to stop it bouncing back vehicle telematics: information monitored and
test plan: document that details the tests to be carried transmitted from vehicles, e.g. their location and speed,
out when a program is complete and whether or not using GPS, engine diagnostics and driving style
they are successful velocity: how quickly data is generated, processed and
text-based programming: written lines of code using a turned into useful information
specific programming language, e.g. Python veracity: accuracy and quality of data
traceback message: displayed when a runtime error is version control: saving each development iteration as a
encountered to help identify where the error occurred new filename to track changes
and what went wrong virtual learning environment (VLE): online classroom
trace table: technique for predicting step by step what where teachers and students can share learning
will happen as each line of an algorithm or program is materials
run, and to identify errors virus scanning: checking files on a computer system for
traditional manufacturing: the making of products malicious content
before computerisation; it often relied on human voice-pattern recognition: software that can
production lines, where people completed individual understand and carry out spoken instructions
tasks, which were passed along the production line until
volume: the massive amounts of data collected and
the final product was complete
analysed on an ongoing basis
transistor: tiny switch activated by electrical signals
Wide Area Network (WAN): type of network where
– when the transistor is ON it represents 1; when the
devices communicate over a large geographical area,
transistor is OFF it represents 0
such as across a city or country
translator: converts program instructions into machine-
wildcard query: query where special characters are used
code format so the processor can carry out the instructions
to stand in for unknown characters (this is useful when
Transmission Control Protocol/Internet Protocol (TCP/ trying to find lots of data items that are similar but not
IP): protocol for transferring data between devices exactly the same)
truth table: breakdown of a logic circuit, listing all wireless access point: allows devices to connect to a
possible operations the logic circuit can carry out network using Wi-Fi

241
369825_Ind_Cam_LSC_SB_242-248.indd Page 242 06/03/23 10:52 AM A4902 /142/HO02737/work/indd

Index
string manipulation 207 decomposition 201–2
A bus topology 61 defragmentation programs 69, 131,
accelerometers 93, 97, 126 133–4
active internet connections 56 device drivers 130, 131, 133
AI see artificial intelligence (AI) C disc defragmentation 69, 131, 133–4
algorithms 4, 5, 13 casting 13 domain names 66
code tracers 19–23 Central Processing Unit (CPU) 140, 141, dry-run testing 22, 27, 53
fragmentation 133 142, 143, 144, 145, 156
see also flowcharts; pseudocode
analogue sound 135
chatbot program 5, 10, 38–53
code tracers 19–23
E
digitisation of 130, 131, 135–7 development iterations 16–18, emerging technologies 154, 155
analogue-to-digital convertor (ADC) 38–44, 52–3 encryption software 69, 76
135–7 error processing 23–8, 45–8 entity relationship diagrams (ERDs) 170
AND logic gate 11, 147, 149 chatbots 8, 11–12, 152 ergonomics 154
antivirus software 57, 133 cloud computing 68, 76–7 error processing 23–8
applications software 129, 132 code tracers 19–23 changing contents of an array 228–9
the APRAnet 57 command lines 80–4 identifying errors and debugging
arrays 6, 35–8, 49–50, 51, 52, 53, 198 compilers 130, 131, 141, 142 225–30
altering contents of 228–30 computerisation 5, 129, 151–3, 157 logic errors 9, 24, 27, 45, 46, 48, 227–8
indexed items 98, 100, 216 concatenation 13 networks 5, 71–3
on the micro:bit 97–102 conditional operators 24, 27, 46, 48, 90, parity-checking systems 72–3,
musical notes 111, 113, 115, 117 147–8 78–80, 85
storing images 116–25 conditional statements 11, 24, 44, 49, 90 runtime errors 9, 24, 45, 46–7, 48,
see also lists; one-dimensional arrays combining logic gates 147–8 225, 228
artificial intelligence (AI) 12, 153 and the micro:bit 94, 124 syntax errors 9, 24, 45–6, 48, 91, 199
and machine learning 150 in Python 210, 211 ethernet cabling 60
and network security 76–7 cookies 152, 153 extreme test data 9, 47, 48, 53, 225
assembly language 140–1, 142, 145 count-controlled loops (for loops) 5, 9, for the micro-bit 95
authentication 75–6 28–30, 37, 44 Python 199, 206, 210–11
in game development 88, 124, 127
B creating a musical sequence F
112–14, 115
Big Data 4, 5–6, 160–97 facial recognition 76, 133, 135, 150, 151
and the micro:bit 103–11
and the 5Vs 163 fetch-decode-execute cycle 5, 130, 131,
in pseudocode 29–30, 33–5, 51–2
analytics 164, 165 143–4, 145, 146, 157
Python 199, 202–6
applications of 163–5 file servers 60, 67, 68, 69
counter variables 106
complex queries 176–81 file storage and retrieval 133
crocodile clips 91
data items 161, 163 fingerprint recognition 76, 133, 134
cyber-attacks 67
data searches 161 firewalls 57, 60, 63, 67, 69, 70, 75, 133
evaluating models of real-life systems flat-file databases 165, 166, 168, 169
185–8 D floats (real data types) 12, 13, 14
social media 160, 163 data accessibility 67–8, 70 flowcharts 9, 9–10, 11, 15, 16, 19
see also databases; relational databases 4, 163, 186, 187, 188–9 game development 88, 90, 127, 232
databases; spreadsheets see also relational databases iteration 31–3, 38–9, 204, 205
binary data 71, 135, 138–9, 140 data storage 130, 131, 138–9, 157 Python 199, 200
binary search 223–4 datasets 74 spreadsheet models 185
biometric security 75–6, 133, 134, 135, logic gates 129 for loops see count-controlled loops (for
150 data types 5, 9, 11, 12–15 loops)
block-based programs 91 in arrays 216
Boolean expressions/operators 130,
131, 147–9, 156, 158, 200
evaluating database models 186
MicroPython 88
G
data types 9, 13, 200 Python 9, 11, 200, 207 game development 5, 6, 88–128
IF statement 211, 213 test plans 9, 47, 48, 53, 225 creating a musical output 111–15

242
369825_Ind_Cam_LSC_SB_242-248.indd Page 243 06/03/23 10:52 AM A4902 /142/HO02737/work/indd

Index

creating your own image 120–3 using iteration with 220–3 connections 56, 57–60
microprocessors 88 see also arrays data packets 55, 64, 65, 71, 74
physical computing devices 88, 89 LLL (low-level languages) 140, 142, 145 disconnection due to interference 56
Python 200, 207, 210–11, 231–5 logic circuits 5, 130, 131, 147, 148–9, error detection 55, 71–3
Tetris 89 156, 158 fit for purpose 55
‘What am I?’ game 90, 111, 125–7 logic errors 9, 24, 27, 45, 46, 48, 227–8 hardware 59–60, 61, 63
see also micro:bit Python 199, 212 packet switching 65
general-purpose input output (GPIO) 91 logic gates 129, 132, 147–8 parity bits 55
graphical user interface (GUI) 80 protocols 55, 64–6, 76
scalability factors 55, 67–70
M storage 67, 70
H machine code 141, 142, 145 sustainable 55
hackers 71, 75 machine learning 129, 130, 131, 150–1, topologies and architecture 55, 56,
high bandwidth connections 56 153, 157 58–9, 61–3, 85–7
HLL (high-level languages) 140, 141, chatbots 12 traffic 60
142, 145 in network security 4, 5, 76–7 user management 69
HTTP (Hypertext Transfer Protocol) 66 potential uses of 151 Nintendo Switch 88, 89
HTTPS (Hypertext Transfer Protocol malware 71, 133 normal test data 9, 47, 48, 53, 225
Secure) 66, 76 manufacturing the micro-bit 95, 96, 123
computerising tasks in 130, 131 Python 199, 206, 210–11
machine learning and NOT logic gate 11, 147, 149
I computerisation in 129
icons 129 many-to-many relationships
IDLE (Integrated Development and in relational databases 170 O
Learning Environment) 11, 200 micro:bit one-dimensional arrays 4, 5, 9, 199
industrial practices, computerisation of accelerometer 93, 97, 126 chatbot program 45
130, 151–3 arrays 97–102 game development 88
Industry 4.0 4, 5, 152–3 and count-controlled loops 103–11 Python 216, 217, 218, 228
integers 9, 12, 13, 14, 21, 97, 99, 217 game development 5, 88, 90, 91–7, 111 one-to-many relationships
integrated development environments creating images 116–25 in relational databases 170,
(IDEs) 46, 48 creating a musical output 111–15 172, 174
Internet Service Providers (ISPS) 58 inputs and outputs 91 one-to-one relationships
interpreters 130, 131, 141, 142 programming 88, 90, 91–7, 100–1 in relational databases 170
invalid test data 9, 47, 48, 53, 225 random library 99, 100–1, 102 operating systems 130, 131, 132, 133,
the micro-bit 95, 96, 123 MicroPython 91 134
Python 199, 206, 210–11 accessing 90 command lines 80
IP addresses 64–5 arrays 97, 98 MOS (network operating systems)
iteration 6, 9, 16–18, 28–38, 52–3, 198, creating the program 110, 115 68–9
199 game development 5, 88, 90 network operating systems (NOS)
error processing 23–8 displaying an image 116–23 68–9
game development 88, 120–7 pseudocode plan 93 OR logic gate 11, 147, 149
login systems 202 MS Access 160, 162, 173–4, 190
program development 38–44 MS Excel 160, 162, 182
Python 9, 17–18, 52–3, 198, 199, 200–6 multiple-criteria queries 176, 180–1 P
using with lists 220–4 multi-table queries 176, 179–80 packet switching 65
statements 9 music 111–15 PANs (Personal Area Networks) 57
version control 120 parameter queries 176, 177–8
see also count-controlled loops (for parity-checking systems 72–3, 78–80,
loops) N 85
naming conventions 14, 97 passwords 75, 133, 134
nesting 124, 125 PINs (personal identification numbers)
L network interface cards (NICs) 59 133, 134
LANs (Local Area Networks) 58, 59, 61 network operating systems (NOS) 68–9, PlayStation 89
linear search 223 70 plug-and-play devices 133, 134
lists 35–7, 216–19, 231 networks 4, 5, 55–87 Pong 89
altering contents of 228–30 accessibility 67–8, 70 power surges 71
searching 223–4 administrators 68, 69, 75 programming languages 140–2, 145
storing 131 command lines 80–4 prototypes 4, 5, 18, 130

243
369825_Ind_Cam_LSC_SB_242-248.indd Page 244 06/03/23 10:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

improving technology 154, 155, 158 robotics 150 test plans 15, 16, 19
micro:bit program codes 126 routers 59, 61, 63, 69 chatbot program 45–8, 53
Python 23, 199 runtime errors 9, 24, 45, 46–7, 48, 199, 225 data types 9, 47, 48, 53, 225
pseudocode 9, 11, 14, 15, 16–17, 19 micro:bit 88, 90, 95, 96, 102, 118–19,
count-controlled (for) loop in 29–30, 123
33–5, 106, 107–8, 110, 111, 204–5 S Python 11, 199, 206, 210–11
creating an image 121–2, 123 security 5, 55, 67, 70, 74–84 Tetris 89
error processing 25 breaches 71 times tables 6
iterative development 16–17, 40, machine learning 4, 5, 76–7 traceback messages 47, 48
43–4, 125 software 75–6, 130, 131, 133, 134, trace tables 6, 9, 16, 18, 19–23, 45,
for a micro:bit program 92, 96, 117, 135, 150 52–3
125, 127 selection 6, 9, 28, 30, 198 debugging a Python program 199
Python 199, 200, 231–2, 233 chatbot program 38, 41 error processing 24, 25–8
trace tables 19–23, 212–13 game development 88, 90, 124 for the micro:bit 88, 103–7, 110,
Python 5, 9, 198–235 nested 124, 125 124–5
count-controlled loops 199, 202–6 sequence 6, 9, 28, 38, 198 creating a musical output 113, 115
data types 9, 11, 200, 207 in game development 88, 90 displaying an image 117
decomposition and sub-programs servers 58, 60 Python 9, 23, 211–15, 221, 222–3
201–2 smartphones 96 traditional manufacturing
identifying errors and debugging Snake 89 computerising tasks in 130, 131,
225–30 social media 160, 163 151–2
IDLE 11, 200 software 4, 129, 132–5 translators 5, 130, 131, 141, 142, 157
IF statement 211, 213 applications software 129, 132 truth tables 156
iterative development 9, 17–18, 52–3, encryption software 69, 76 tuples 216, 217
198, 199, 200–6 network utilities 69, 70
lists 35–7, 216–19 security software 75–6, 130, 131,
using iteration with 220–3 133, 134, 135, 150 U
prototypes 23, 199 spreadsheets 181–4 user access controls 75
running 145 systems software 68–9, 70, 129, 132, user requirements 186
string manipulation 9, 199, 207–11 157 utilities software 130, 131, 132, 133,
test plan 11, 199, 206, 210–11 utilities software 130, 131, 132, 134, 134, 136, 157
trace tables 9, 23, 211–15, 221, 222–3 136, 157
tuples 216, 217 see also operating systems
variables 211, 216, 233 spreadsheets 4, 161, 163, 189–90 V
see also chatbot program data analysis 161 variable data collection 12–15
models 6, 161, 162, 181–4, 191 variables 18, 19, 211, 216, 233
creating 194–5 counter variables 106
Q evaluating 187–8, 197 vehicle telematics 164
Query by Example (QBE) 190–1, 192 star topology 62–3, 63 version control 120
questioning 8, 10 strings 12, 13, 14, 21 virus scanning backup 69
in arrays 36, 97 VLE (virtual learning environment)
converting variables to 109 161–2, 192, 194, 195, 197
R len(i) function 209 voice-pattern recognition 133, 134
radio frequency identification (RFID) manipulation 4, 5, 49
tags 152, 153 in Python 9, 199, 207–11, 219
random access memory (RAM) 133, 134 Structured Query Language (SQLs) 190, W
relational databases 5–6, 161, 162, 192 WANs (Wide Area Networks) 58, 59, 61
165–75 syntax errors 9, 24, 45–6, 48, 91, 199 while true code 99
creating 170–5, 192–4 systems software 68–9, 70, 129, 132, wildcat queries 176, 178–9, 181
data dictionaries 171, 172 134, 135, 157 wireless access point 59
foreign keys 167, 168, 169, 170, 174 see also operating systems
input masks 171, 172
primary keys 167, 168, 169, 170, 171, X
174 T Xbox 89
validation 171, 172 TCP/IP Protocol 64–5
ring topology 62, 63 terminators 61

244
369825_Ind_Cam_LSC_SB_242-248.indd Page 245 09/03/23 8:51 AM A4902 /Data%20Disk/Manoj%20R/2023/March/09-03-23/HO02737_142

Acknowledgements
The Publishers would like to thank the following for permission to reproduce copyright material.

Photo credits
p. 8 t © Coosh448/stock.adobe.com, b © Thapana_Studio/stock.adobe.com; p. 11 © Zapp2photo/
stock.adobe.com; p. 55 © Metamorworks/stock.adobe.com; p. 56 © Parilov/stock.adobe.com; p. 57 t
© Aitorserra/stock.adobe.com, b © Yurakrasil/stock.adobe.com; p. 58 t © Metamorworks/stock.adobe.
com, m © Paisan1leo/stock.adobe.com; p. 59 in descending order © Vadim/stock.adobe.com, ©
Sergey Ilin/stock.adobe.com, © An-T/stock.adobe.com, © Quality Stock Arts/stock.adobe.com;
p. 60 in descending order © Cybrain/stock.adobe.com, © MicroOne/stock.adobe.com, © RankSol/
stock.adobe.com; p. 64 © PCH.Vector/stock.adobe.com; p. 66 © WENN Rights Ltd/Alamy Stock Photo;
p. 68 t © WrightStudio/stock.adobe.com, b © Chaosamran_Studio/stock.adobe.com; p. 71 © Vitalii/
stock.adobe.com; p. 74 © Issaronow/stock.adobe.com; p. 75 © Kt Stock/stock.adobe.com; p. 88 ©
Rosinka79/stock.adobe.com; p. 89 t © Bohdan/stock.adobe.com, m © Oleksandr/stock.adobe.com,
b © Gorodenkoff/stock.adobe.com; p. 91 © Gargantiopa/Shutterstock.com; p. 96 © Jeler/stock.
adobe.com; p. 129 © Macrovector/stock.adobe.com; p. 130 © Adam121/stock.adobe.com; p. 133 ©
Prostock-studio/stock.adobe.com; p. 135 © DGTL Graphics sro/stock.adobe.com; p. 142 © ZinetroN/
stock.adobe.com; p. 147 © Frozen Design/stock.adobe.com; p. 150 © Sammby/Shutterstock.com;
p. 151 © Ico Maker/Shutterstock.com; p. 154 t © Bongkochrut/stock.adobe.com, ml © Gorodenkoff/
stock.adobe.com, m © Gorodenkoff/stock.adobe.com, mr © Gorodenkoff/stock.adobe.com; p. 155
t © Sakinakhanim/Shutterstock.com, b © Stakes/Shutterstock.com; p. 156 in descending order ©
Flatvector/Shutterstock.com, © Agatha-vector/Shutterstock.com, © Andrii/stock.adobe.com; p. 160 ©
Scanrail/stock.adobe.com; p. 161 © Natee Meepian/stock.adobe.com; p. 162 © Merla/stock.adobe.
com; p. 176 © Dimon_ua/stock.adobe.com; p. 181 © Wachiwit/stock.adobe.com; p. 185 © Worawut/
stock.adobe.com; p. 202 © Jane Kelly/stock.adobe.com.

Text credits
The following brands mentioned in this book are trademarks or registered trademarks:
● Android ● Dropbox ● Google.com
● Google Drive ● Google Maps ● iOS
● Javascript ● Linux ● macOS
● Mozilla ● micro:bit ● MicroPython
● Microsoft Access ● Microsoft Excel ● Microsoft OneDrive
● Microsoft Powerpoint ● Microsoft Windows ● Microsoft Word
● MS-DOS ● Nintendo Switch ● Netflix
● Pong ● Python ● Python’s Integrated Development
and Learning Environment

245
369825_Ind_Cam_LSC_SB_242-248.indd Page 246 06/03/23 10:52 AM A4902 /142/HO02737/work/indd

CAMBRIDGE LOWER SECONDARY COMPUTING 9

● Playstation ● MakeCode ● Scratch


● Snake ● Spotify ● Tetris
● UPS ● Wi-Fi ● Windows Explorer
● Xbox
BBC micro:bit images and screenshots © Micro:bit Educational Foundation microbit.org
Google, Google Drive and Google Maps are trademarks of Google LLC and this book is not endorsed
by or affiliated with Google in any way.
MicroPython copyright © 2013-2022 Damien P. George, https://github.com/micropython/
micropython/blob/master/LICENSE
Microsoft product screenshot(s) used with permission from Microsoft.
Python copyright © 2001-2022 Python Software Foundation; All Rights Reserved.
Every effort has been made to trace all copyright holders, but if any have been inadvertently
overlooked, the Publishers will be pleased to make the necessary arrangements at the first
opportunity.
Although every effort has been made to ensure that website addresses are correct at time of going to
press, Hodder Education cannot be held responsible for the content of any website mentioned in this
book. It is sometimes possible to find a relocated web page by typing in the address of the home page
for a website in the URL window of your browser.

246
369825_Ind_Cam_LSC_SB_242-248.indd Page 247 06/03/23 10:52 AM A4902 /142/HO02737/work/indd
369825_Ind_Cam_LSC_SB_242-248.indd Page 248 06/03/23 10:52 AM A4902 /142/HO02737/work/indd

You might also like