algorithm design and problem solving
algorithm design and problem solving
Computer Science
Development Life Cycle
Contents
Program Development Life Cycle
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Program Development Life Cycle
Your notes
Analysis
What is the analysis stage of the program development
life cycle?
The analysis stage of the program development life cycle is to precisely understand the
problem the program is intended to solve
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Core functionality
Using abstraction helps to identify the fundamental components of what the program Your notes
is going to solve
Before tackling a problem, it needs to be clearly understood by everyone working on it
The overall goal of the solution needs to be agreed as well as any constraints such as
limited resources or requiring a platform specific solution
Requirements
To create a solution, a requirements document is created to define the problem and
break it down into clear, manageable, understandable parts by using abstraction and
decomposition
A requirements document labels each requirement, gives it a description as well as
success criteria which state how we know when the requirement has been achieved
Design
What is the design stage of the program development
life cycle?
The design stage of the program development life cycle involves using techniques to
come up with a blueprint for a solution
Ways the design of a solution to a problem can be presented include:
Structure diagrams
Flowchart
Pseudocode
Coding
What is the coding stage of the program development
life cycle?
Developers begin programming modules in a suitable programming language that
works together to provide an overall solution to the problem
As each developer programs, they perform iterative testing
Iterative testing is where each module is tested and debugged thoroughly to make
sure it interacts correctly with other modules and accepts data without crashing or
causing any errors
Developers may need to retest modules as new modules are created and changed to
make sure they continue to interact correctly and do not cause errors
Testing
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
What is the testing stage of the program development
life cycle? Your notes
Once the overall program or set of programs is created, they are run many times using
varying sets of test data
This ensures the program or programs work as intended as outlined in the initial
requirements specification and design and rejects any invalid data that is input
Examples of test data include alphanumeric sequences to test password validation
routines
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
Cambridge (CIE) IGCSE Your notes
Computer Science
Computer Sub-Systems
Contents
Computer Sub-Systems
Problem Decomposition
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Computer Sub-Systems
Your notes
Computer Sub-Systems
What is a sub-system?
A sub-system is a smaller part of a computer system that works together with other
sub-systems to create fully functional computer system
A car is a great example of using sub-systems
A car will only function if its sub-systems all work together, they are:
Engine
Breaks
Wheels etc.
Sub-systems can be further broken down into even smaller sub-systems such as:
Engine - spark plugs, sensors, pistons
In computers, there are five main sub-systems:
Executes Stores data & Stores data and Allows a user to Displays
instructions instructions software enter information or
temporarily for permanently information creates a
the CPU (RAM) (HDD, SSD) (keyboard, physical output
mouse) (monitor, printer)
Computer sub-systems can be further broken down into smaller sub-systems such as:
CPU - control unit, registers & arithmetic logic unit (ALU)
Advantages of sub-systems
Can help troubleshoot problems in a computer system
The ability to isolate a sub-system makes it easier to identify and fix issues, as each
sub-system can be examined separately
Developing software relies on the use of different sub-systems to ensure they operate
efficiently
Gives developers and designers a clear picture of how sub-systems help build complex
systems
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
Problem Decomposition
Your notes
Problem Decomposition
What is decomposition?
Decomposition is the process of breaking down a large problem into a set of smaller
problems
Benefits of decomposition are:
Smaller problems are easier to solve
Each smaller problem can be solved independently of the others
Smaller problems can be tested independently
Smaller problems can be combined to produce a solution to the full problem
Modern computer games are a good example of using decomposition to break down
the complexity of the problem into more manageable 'chunks'
Creating an entire game at once would be challenging and inefficient, so it could be
decomposed into:
Levels - Levels can be designed/created/tested/ independently of other levels
Characters - The mechanics of characters in the game can be designed and
created by a separate team
Landscape - The art team can work on the visual aspects of the game without
needing to understand how the game is programmed
Once all of the smaller problems are completed, joined together a complex game has
been created
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Processes Width x height
Your notes
Outputs Calculated area of the rectangle
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
Cambridge (CIE) IGCSE Your notes
Computer Science
Algorithms
Contents
Designing Algorithms
Explaining Algorithms
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Designing Algorithms
Your notes
What is an algorithm?
An algorithm is precise set of rules or instructions to solve a specific problem or task
There are three main ways to design an algorithm
Structure diagrams
Flowchart
Pseudocode
Structure Diagrams
What is a structure diagram?
Structure diagrams show hierarchical top-down design in a visual form
Each problem is divided into sub-problems and each sub-problem divided into further
sub-problems
At each level the problem is broken down into more detailed tasks that can be
implemented using a single subroutine
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
Your notes
Flowcharts
What is a flowchart?
Flowcharts are a visual tool that uses shapes to represent different functions to
describe an algorithm
Flowcharts show the data that is input and output, the processes that take place and
any decisions or repetition
Lines are used to show the flow of control
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Example
Flowchart Your notes
The casino would like the algorithm refined so that the user also enters their first name
and this is used to greet the user when they access the site
Flowchart
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
Your notes
Pseudocode
What is pseudocode?
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
Pseudocode is a text-based tool that uses short English words/statements to
describe an algorithm
Your notes
Pseudocode is more structured than writing sentences in English but is very flexible
Example
A casino would like a program that asks users to enter an age, if they are 18 or over they
can enter the site, if not then they are given a suitable message
Pseudocode
INPUT Age
IF Age >= 18
THEN
OUTPUT "Welcome to the site"
ELSE
OUTPUT "Sorry, this site is for users 18 and over"
ENDIF
The casino would like the algorithm refined so that the user also enters their first name
and this is used to greet the user when they access the site
Pseudocode
INPUT FName
INPUT Age
IF Age >= 18
THEN
OUTPUT "Welcome to the site", FName
ELSE
OUTPUT "Sorry, this site is for users 18 and over"
ENDIF
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
Explaining Algorithms
Your notes
Explaining Algorithms
How do you explain an algorithm?
A well designed algorithm should be able to be interpreted by a new user and they
should be able to explain what it does
Algorithms can be written using flowcharts, pseudocode or high-level programming
language code such as Python
The purpose of an algorithm is to solve a problem, if a user does not know the goal of the
algorithm, then following the algorithm instructions should make its purpose clear
If the algorithm is complex then additional ways to understand the problem could be:
Look for comments in the code
Consider the context of where the algorithm is being used
Test the algorithm with different inputs
Look at the following algorithm, can you explain what it does?
Pseudocode
Count ← 1
Number ← 0
Total ← 0
REPEAT
INPUT Number
Total ← Total + Number
Count ← Count + 1
UNTIL Count > 10
OUTPUT Total
The purpose of the algorithm is to add ten user-entered numbers together and output
the total
The processes are:
initializing three variables (Count, Number, Total)
inputting a user number
adding to two variables (Total, Count)
repeating nine more times
outputting the final Total value
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
Worked Example
The pseudocode algorithm shown has been written by a teacher to enter marks for Your notes
the students in her class and then to apply some simple processing.
Count ← 0
REPEAT
INPUT Score[Count]
Count ← Count + 1
UNTIL Count = 30
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
Cambridge (CIE) IGCSE Your notes
Computer Science
Standard Methods of a Solution
Contents
Linear Search & Bubble Sort
Other Standard Methods of a Solution
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Linear Search & Bubble Sort
Your notes
Linear Search
What is a searching algorithm?
Searching algorithms are precise step-by-step instructions that a computer can follow
to efficiently locate specific data in massive datasets
4 REPEAT UNTIL you have checked all values and not found the value you are looking
for
// Declare variables
DECLARE data : ARRAY[1:5] OF INTEGER
DECLARE target : INTEGER
DECLARE found : BOOLEAN
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
target ← 11
found ← FALSE // Start with the assumption that the target is not found
Your notes
// Loop through each element in the array
FOR index ← 1 TO 5
// Check if the current element matches the target
IF data[index] = target THEN
found ← TRUE
OUTPUT "Target found"
ENDIF
NEXT index
# Identify the dataset to search, the target value and set the initial flag
data = [5, 2, 8, 1, 9]
target = 11
found = False
Bubble Sort
What is a sorting algorithm?
Sorting algorithms are precise step-by-step instructions that a computer can follow
to efficiently sort data in massive datasets
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
How do you perform a bubble sort?
Your notes
Step Instruction
4 REPEAT step 2 & 3 until you reach the end of the dataset (pass 1)
Example
Perform a bubble sort on the following dataset
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
5 2 4 1 6 3
Your notes
Step Instruction
5 2 4 1 6 3
2 5 4 1 6 3
2 5 4 1 6 3
4 REPEAT step 2 & 3 until you reach the end of the dataset
5 & 4 SWAP!
2 4 5 1 6 3
5 & 1 SWAP!
2 4 1 5 6 3
5 & 6 NO SWAP!
2 4 1 5 6 3
6 & 3 SWAP!
2 4 1 5 3 6
End of pass 1
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
2 1 4 3 5 6
Your notes
End of pass 3 (swaps made)
1 2 3 4 5 6
1 2 3 4 5 6
// Loop through the array from the start to the second-last unsorted element
FOR y ← 1 TO numlength - 1
// If the current number is greater than the next number, swap them
IF nums[y] > nums[y + 1] THEN
DECLARE temp : INTEGER
temp ← nums[y]
nums[y] ← nums[y + 1]
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
nums[y + 1] ← temp
# Unsorted dataset
nums = [66, 7, 69, 50, 42, 80, 71, 321, 67, 8, 39]
Worked Example
A program uses a file to store a list of words.
Show the stages of a bubble sort when applied to data shown [2]
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
How to answer this question
We need to sort the values in to alphabetical order from A-Z Your notes
You CAN use the first letter of each word to simplify the process
Answer
E, B, C, M, G, P (pass 1)
B, C, E, G, M, P (pass 2)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
Other Standard Methods of a Solution
Your notes
Totalling & Counting
What is totalling?
Totalling is keeping a running total of values entered into the algorithm
An example may be totalling a receipt for purchases made at a shop
In the example below, the total starts at 0 and adds up the user inputted value for each
item in the list
Pseudocode
Total ← 0
FOR Count ← 1 TO ReceiptLength
INPUT ItemValue
Total ← Total + itemValue
NEXT Count
OUTPUT Total
What is counting?
Counting is when a count is incremented or decremented by a fixed value, usually 1,
each time it iterates
Counting keeps track of the number of times an action has been performed
Many algorithms use counting, including the linear search to track which element is
currently being considered
In the example below, the count is incremented and each pass number is output until
fifty outputs have been produced
Pseudocode
Count ← 0
DO
OUTPUT “Pass number”, Count
Count ← Count + 1
UNTIL Count >= 50
In the example below, the count is decremented from fifty until the count reaches zero.
An output is produced for each pass
Pseudocode
Count ← 50
DO
OUTPUT “Pass number”, Count
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 9
Count ← Count - 1
UNTIL Count <= 0
Your notes
Pseudocode
Total ← 0
Scores ← [25, 11, 84, 91, 27]
Highest ← max(Scores)
Lowest ← min(Scores)
# Calculate average
Average ← Total / LENGTH(Scores)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 10
Cambridge (CIE) IGCSE Your notes
Computer Science
Validation & Verification
Contents
Validation & Verification
Suitable Test Data
Trace Tables
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Validation & Verification
Your notes
Validation
What is validation?
Validation is an automated process where a computer checks if a user input is sensible
and meets the program's requirements.
There are six categories of validation which can be carried out on fields and data types,
these are
Range check
Length check
Type check
Presence check
Format check
Check digit
There can be occasions where more than one type of validation will be used on a field
An example of this could be a password field which could have a length, presence and
type check on it
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
Your notes
Range check
Ensures the data entered as a number falls within a particular range
Python Ensures a user's age has been entered and falls between the digits of 0-110
inclusive
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Length check
Checks the length of a string Your notes
password_length = len(password)
while password_length < 8:
password = input("Enter a password which is 8 or more characters")
Type check
Check the data type of a field
Presence check
Looks to see if any data has been entered in a field
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
OUTPUT “Enter your username”
REPEAT
INPUT Username Your notes
IF Username = “”
THEN
OUTPUT “No username entered, please try again”
ENDIF
UNTIL Username <> “”
Python Ensures when registering for a website the name field is not left blank
Format check
Ensures that the data has been entered in the correct format
Format checks are done using pattern matching and string handling
Pseudocode Ensures a six digit ID number is entered against the format "XX9999"
where X is an uppercase alphabetical letter and 9999 is a four digit
number
INPUT IDNumber
IF LENGTH(IDNumber) <> 6
THEN
OUTPUT "ID number must be 6 characters long"
END IF
ValidChars ← "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FirstChar ← SUBSTRING(IDNumber, 1, 1)
ValidChar ← False
Index ← 1
IF ValidChar = False
THEN
OUTPUT "First character is not a valid uppercase alphabetical character"
ENDIF
SecondChar ← SUBSTRING(IDNumber, 2, 2)
ValidChar ← False
Index ← 1
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
WHILE Index <= LENGTH(ValidChars) AND ValidChar = False DO
IF SecondChar = ValidChars[Index] Your notes
THEN
ValidChar ← True
ENDIF
Index ← Index + 1
ENDWHILE
IF ValidChar = False
THEN
OUTPUT "Second character is not a valid uppercase alphabetical character"
ENDIF
Explanation
The first two characters are checked against a list of approved characters
The first character is compared one at a time to each valid character in the ValidChars
array
If it finds a match it stops looping and sets ValidChar to True
The second character is then compared one at a time to each valid character in the
ValidChars array
If it finds a match then it also stops looping and sets ValidChar to True
Casting is used on the digits to turn the digit characters into numbers
Once the digits are considered a proper integer they can be checked to see if they
are in the appropriate range of 0-9999
If any of these checks fail then an appropriate message is output
Python Ensures an email contains a '@' and ' full stop (.) which follows the format
"[email protected]"
Check digits
Check digits are numerical values that are the final digit of a larger code such as a
barcode or an International Standard Book Number (ISBN)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
They are calculated by applying an algorithm to the code and are then attached to the
overall code
Your notes
Verification
What is verification?
Verification is the act of checking data is accurate when entered into a system
Mistakes such as creating a new account and entering a password incorrectly mean
being locked out of the account immediately
Verification methods include:
double entry checking
visual checks
Pseudocode
REPEAT
OUTPUT “Enter your password”
INPUT Password
OUTPUT “Please confirm your password”
INPUT ConfirmPassword
IF Password <> ConfirmPassword
THEN
OUTPUT “Passwords do not match, please try again”
ENDIF
UNTIL Password ← ConfirmPassword
Visual checks
Visual checks involve the user visually checking the data on the screen
A popup or message then asks if the data is correct before proceeding
If it isn’t the user then enters the data again
Pseudocode
REPEAT
OUTPUT “Enter your name”
INPUT Name
OUTPUT “Your name is: “, Name, “. Is this correct? (y/n)”
INPUT Answer
UNTIL Answer ← “y”
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
Your notes
Worked Example
Describe the purpose of validation and verification checks during data entry. Include
an example for each.
[4]
Answers
Validation check
[1] for description:
To test if the data entered is possible / reasonable / sensible
A range check tests that data entered fits within specified values
[1] for example:
Range / length / type / presence / format
Verification check
[1] for description:
To test if the data input is the same as the data that was intended to be input
A double entry check expects each item of data to be entered twice and
compares both entries to check they are the same
[1] for example:
Visual / double entry
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
Suitable Test Data
Your notes
Suitable Test Data
What is suitable test data?
Suitable test data is specially chosen to test the functionality of a program or design
Developers or test-users would pick a selection of test data from the following
categories
Normal
Abnormal
Extreme
Boundary
The results would be compared to the expected results to check if the
algorithm/program works as intended
Each category is explained within the context of a simple Python program below,
comments have been added to help explain the processes
Python
Normal data
Normal test data is data that should be accepted in the program
An example would be a user entering their age as 16 into the age field of the program
Abnormal data
Abnormal test data is data that is the wrong data type
An example would be a user entering their age as "F" into the age field of the program
Extreme data
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 9
Extreme test data is the maximum and minimum values of normal data that are
accepted by the system
Your notes
An example would be a user entering their age as 18 or 12 into the age field of the
program
Boundary data
Boundary test data is similar to extreme data except that the values on either side of the
maximum and minimum values are tested
The largest and smallest acceptable value is tested as well as the largest and smallest
unacceptable value
An example would be a user entering their age as 11 or 19 into the age field of the program
Normal 14 Accepted
Normal 16 Accepted
Extreme 12 Accepted
Extreme 18 Accepted
Abnormal H Rejected
Abnormal @ Rejected
Boundary 11 Rejected
Boundary 19 Rejected
Worked Example
A programmer has written an algorithm to check that prices are less than $10.00
These values are used as test data: 10.00 9.99 ten
State why each value was chosen as test data.
[3]
Answers
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 10
10.00 is boundary or abnormal data and should be rejected as it is out of range [1]
9.99 is boundary, extreme and normal data and should be accepted as it is within the Your notes
normal range [1]
Ten is abnormal data and should be rejected as it is the wrong value type [1]
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 11
Trace Tables
Your notes
Trace Tables
What is a trace table?
A trace table is used to test algorithms and programs for logic errors that appear when
an algorithm or program executes
Trace tables can be used with flowcharts, pseudocode or program code
A trace table can be used to:
Discover the purpose of an algorithm by showing output data and intermediary
steps
Record the state of the algorithm at each step or iteration
Each stage of the algorithm is executed step by step.
Inputs, outputs, variables and processes can be checked for the correct value when the
stage is completed
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 12
Your notes
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 13
4 Enter your first number
Your notes
2 3 Enter your next number
3 7 7
4 1
5 8 8
6 3
7 6
8 9 9
9 12 12
Worked Example
The flowchart represents an algorithm. The algorithm will terminate if –1 is entered.
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 14
Your notes
Complete the trace table for the input data: 50, 75, 99, 28, 82, 150, –1, 672, 80
[4]
Answer
[1] for each correct column
50 50 0 Accept: Extreme
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 15
75 25 25 Accept: Normal
28 Reject: Abnormal
82 18 32 Accept: Normal
-1
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 16
Cambridge (CIE) IGCSE Your notes
Computer Science
Identifying Errors
Contents
Identifying Errors
Writing & Amending Algorithms
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Identifying Errors
Your notes
Identifying errors
Designing algorithms is a skill that must be developed and when designing algorithms,
mistakes and issues will occur
Trace tables can also help to find any kind of error in a program or algorithm
There are three main categories of errors that when designing algorithms a programmer
must be able to identify & fix, they are:
Syntax errors
Logic errors
Runtime errors
Syntax Errors
What is a syntax error?
A syntax error is an error that breaks the grammatical rules of a programming language
and stops it from running
Examples of syntax errors are:
Typos and spelling errors
Missing or extra brackets or quotes
Misplaced or missing semicolons
Invalid variable or function names
Incorrect use of operators
Incorrectly nested loops & blocks of code
def main():
# -----------------------------------------------------------------------
# Prompts the user for personal information and displays a suggested username
# -----------------------------------------------------------------------
first_name = imput("Enter your first name: ")
last_name = input("Enter your last name: ")
usdrname = generate_username(first_name, last_name)
print(f"Here's a suggested username: {username}")
# ------------------------------------------------------------------------
# Main program
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
# ------------------------------------------------------------------------
main
Your notes
Python code - without syntax errors
def main():
# -----------------------------------------------------------------------
# Prompts the user for personal information and displays a suggested username
# -----------------------------------------------------------------------
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
username = generate_username(first_name, last_name)
print(f"Here's a suggested username: {username}")
# ------------------------------------------------------------------------
# Main program
# ------------------------------------------------------------------------
main()
Syntax errors
Logic Errors
What is a logic error?
A logic error is where incorrect code is used that causes the program to run, but
produces an incorrect output or result
Logic errors can be difficult to identify by the person who wrote the program, so one
method of finding them is to use 'Trace Tables'
Examples of logic errors are:
Incorrect use of operators (< and >)
Logical operator confusion (AND for OR)
Looping one extra time
Indexing arrays incorrectly (arrays indexing starts from 0)
Using variables before they are assigned
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
Infinite loops
Python code
Your notes
def calculate_area(length, width):
###
Calculates the area of a rectangle
Inputs:
length (float): The length of the rectangle (positive value)
width (float): The width of the rectangle (positive value)
Returns:
float: The calculated area of the rectangle
Raises:
ValueError: If either length or width is non-positive
###
if length < 0 or width < 0:
raise ValueError("Length and width must be positive values.")
area = length * width
return area
def main():
# -----------------------------------------------------------------------
Prompts the user for rectangle dimensions and prints the calculated area
# -----------------------------------------------------------------------
try:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Call the area calculation function
area = calculate_area(length, width)
print(f"The area of the rectangle is approximately {area:.2f} square units.")
except ValueError as error:
print(f"Error: {error}")
# -----------------------------------------------------------------------
# Main program
# -----------------------------------------------------------------------
main()
Logic errors
Test Test Expected outcome Actual outcome Changes
number data needed? (Y/N)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
2 Length "Length and width "The area of the Y
= 10 must be positive rectangle is should not
Your notes
values." approximately 0.00 accept 0 input
Width = square units." as not positive
0
Runtime Errors
What is a runtime error?
A runtime error is where an error causes a program to crash
Examples of runtime errors are:
Dividing a number by 0
Index out of the range of an array
Unable to read or write a drive
Python code
def main():
# -----------------------------------------------------------------------
Prompts the user for rectangle dimensions and prints the calculated area
# -----------------------------------------------------------------------
try:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Call the area calculation function
area = calculate_area(length, width)
print(f"The area of the rectangle is approximately {area:.2f} square units.")
except ValueError as error:
print(f"Error: {error}")
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
# -----------------------------------------------------------------------
# Main program
# ----------------------------------------------------------------------- Your notes
main()
Runtime errors
Test Test Expected outcome Actual outcome Changes
number data needed? (Y/N)
Runtime error identified as missing iteration (while loop) so program does not ask user
to enter width and height again
Corrected code now includes a while loop
while True:
try:
length = float(input("Enter the length of the rectangle: "))
width = float(input("Enter the width of the rectangle: "))
# Call the area calculation function
area = calculate_area(length, width)
print(f"The area of the rectangle is approximately {area:.2f} square units.")
break # Exit the loop if successful
except ValueError as error:
print(f"Error: {error}")
print("Please enter positive values for length and width.")
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
Writing & Amending Algorithms
Your notes
Algorithmic Thinking
What is algorithmic thinking?
Algorithmic thinking is the process of creating step-by-step instructions in order to
produce a solution to a problem
Algorithmic thinking requires the use of abstraction and decomposition to identify each
individual step
Once each step has been identified, a precise set of rules (algorithm) can be created
and the problem will be solved
An example of algorithmic thinking is following a recipe, if the recipe is followed
precisely it should lead to the desired outcome
A set of traffic lights is an example of how algorithmic thinking can lead to solutions
being automated
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
Be sure to use variable names and data provided in the question as given. Failure to do
so will lose you marks
Your notes
Remember to comment on your code. It helps both you and the examiner understand
your answer and also awards marks in the mark scheme!
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8