25 Programming Concepts
25 Programming Concepts
Page 1 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Data Types
Your notes
Data Types
A data type is a classification of data into groups according to the kind of data they represent
Computers use different data types to represent different types of data in a program
The basic data types include:
Integer: used to represent whole numbers, either positive or negative
Examples: 10, -5, 0
Real: used to represent numbers with a fractional part, either positive or negative
Examples: 3.14, -2.5, 0.0
Char: used to represent a single character such as a letter, digit or symbol
Examples: 'a', 'B', '5', '$'
String: used to represent a sequence of characters
Examples: "Hello World", "1234", "@#$%
Boolean: used to represent true or false values
Examples: True, False
We can declare variables as follows:
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the
program.
Page 2 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Worked example
Your notes
Name and describe the most appropriate programming data type for each of the examples of data
given. Each data type must be different
[6]
Data: 83
Data type name: Integer [1]
Data type description: The number is a whole number [1]
Data: [email protected]
Data type name: String [1]
Data type description: It is a group of characters [1]
Data: True
Data type name: Boolean [1]
Data type description: The value is True (or could be False) [1]
Page 3 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Examples in Pseudocode:
Declare a variable called 'score' with a value of 10
score ← 10
Examples in Python:
Declare a variable called 'score' with a value of 10
score = 10
Examples in Java:
Declare a variable called 'score' with a value of 10
int score = 10;
Page 4 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Exam Tip
Exam questions will ask you to write pseudocode statements, rather than in a specific language
Worked example
The variables 'name' and 'age' are used to store data in a program:
name stores the user’s name
age stores the user’s age
Write pseudocode statements to declare the variables name and age.
[2]
DECLARE name : STRING [1]
DECLARE age : INTEGER [1]
Page 5 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Pseudocode example:
OUTPUT "Hello, ", name
Python example:
print("Hello, ", name)
Java example:
System.out.println("Hello, " + name);
Page 6 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Input
Input refers to the process of providing data or information to a program. Your notes
'User Input' is data or information entered by the user during program execution.
Pseudocode example:
OUTPUT "Enter your name"
INPUT name
Python example:
name = input("Enter your name: ")
Java example:
Scanner input = new Scanner(System.in);
name = Console.Readline()
Exam Tip
Remember to prompt the user for input clearly, and format the output to make it readable and
understandable.
Page 7 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Sequence
Your notes
Sequence
What is Sequence?
Sequence is a concept that involves executing instructions in a particular order
It is used in programming languages to perform tasks in a step-by-step manner
Sequence is a fundamental concept in computer science and is used in many programming languages
Pseudocode example:
PRINT "Hello, World!"
x←5
y←10
z← x + y
PRINT z
Python example:
print("Hello, World!")
x=5
y = 10
z=x+y
print(z)
Java example:
System.out.println("Hello, World!");
int x = 5;
int y = 10;
int z = x + y;
System.out.println(z);
Page 8 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Console.WriteLine("Hello, World!")
Dim z As Integer = x + y
Console.WriteLine(z)
Exam Tip
Always remember to write your instructions in the order in which you want them to be executed
Page 9 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Selection
Your notes
Selection
What is selection?
Selection is a programming concept that allows you to execute different sets of instructions based on
certain conditions. There are two main types of selection statements: IF statements and CASE statements.
Page 10 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
If Statements
IF statements allow you to execute a set of instructions if a condition is true. They have the following syntax: Your notes
IF condition
THEN
instructions
ENDIF
Pseudocode example:
x← 5
IF x > 0
THEN
ENDIF
Python example:
x=5
if x > 0:
print("x is positive")
Java example:
int x = 5;
if (x > 0) {
System.out.println("x is positive");
If x > 0 Then
Console.WriteLine("x is positive")
Page 11 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
End If
Your notes
IF ELSE Statements
If else statements are used to execute one set of statements if a condition is true and a different set of
statements if the condition is false. They have the following syntax:
IF condition
THEN
Instructions
ELSE
Instructions
ENDIF
Pseudocode example:
x←5
IF x > 0
THEN
ELSE
PRINT “x is negative”
ENDIF
Python example:
x=5
if x > 0:
print("x is positive")
else:
print("x is negative")
Java example:
Page 12 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
int x = 5;
} else {
System.out.println("x is negative");
If x > 0 Then
Console.WriteLine("x is positive")
Else
Console.WriteLine("x is negative")
End If
IF ELSE IF Statements
If else if statements are used to test multiple conditions and execute different statements for each
condition. They have the following syntax:
IF condition
THEN
Instructions
ELSE IF condition
THEN
Instructions
ELSE
Instructions
ENDIF
Pseudocode example:
Page 13 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
x← 5
ELSE IF x < 0
THEN
PRINT “x is negative”
ELSE
PRINT “x is 0”
ENDIF
Python example:
x=5
if x > 0:
print("x is positive")
elif x < 0:
print("x is negative")
else:
print("x is 0")
Java example:
int x = 5;
if (x > 0) {
System.out.println("x is positive");
} else if (x < 0) {
System.out.println("x is negative");
} else {
Page 14 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
System.out.println("x is 0");
} Your notes
Visual Basic example:
Dim x As Integer = 5
If x > 0 Then
Console.WriteLine("x is positive")
Console.WriteLine("x is negative")
Else
Console.WriteLine("x is 0")
End If
Worked example
Write an algorithm using pseudocode that:
Inputs 3 numbers
Outputs the largest of the three numbers
[3]
INPUT a, b, c
IF a > b AND a > c THEN PRINT a [1]
ELSE IF b > c THEN PRINT b [1]
ELSE PRINT c [1]
Page 15 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Case Statements
CASE statements allow you to execute different sets of instructions based on the value of a variable. They Your notes
have the following syntax:
CASE OF variable
value1: instructions
value2: instructions
...
OTHERWISE instructions
END CASE
Pseudocode example:
CASE OF number
1: PRINT "Monday"
2: PRINT "Tuesday"
3: PRINT “Wednesday”
4: PRINT “Thursday”
5: PRINT “Friday”
6: PRINT “Saturday”
7: PRINT “Sunday”
END CASE
Python example:
match (number)
case 1:
print "Monday";
case 2:
print "Tuesday";
Page 16 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
case 3:
print "Thursday";
case 5:
print "Friday";
case 6:
print "Saturday";
case 7:
print "Sunday";
case _:
Java example:
switch (number) {
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
Page 17 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
return "Saturday";
default:
Case 1
Return "Monday"
Case 2
Return "Tuesday"
Case 3
Return "Wednesday"
Case 4
Return "Thursday"
Case 5
Return "Friday"
Case 6
Return "Saturday"
Case 7
Return "Sunday"
Case Else
End Select
Page 18 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Exam Tip
Your notes
Make sure to include all necessary components in the selection statement: the condition, the
statement(s) to execute when the condition is true, and any optional statements to execute when
the condition is false
Use proper indentation to make the code easier to read and understand
Be careful with the syntax of the programming language being used, as it may differ slightly
between languages
Make sure to test the selection statement with various input values to ensure that it works as
expected
Page 19 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Iteration
Your notes
Iteration
What is iteration?
Iteration is the process of repeating a set of instructions until a specific condition is met. It is an important
programming concept and is used to automate repetitive tasks.
There are three main types of iteration:
Count-controlled loops
Precondition loops
Postcondition loops
Page 20 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Count-controlled Loops
A count-controlled loop is used when the number of iterations is known beforehand Your notes
It is also known as a definite loop
It uses a counter variable that is incremented or decremented after each iteration
The loop continues until the counter reaches a specific value
Example in Pseudocode:
count ← 1
FOR i <= 10
OUTPUT count
NEXT i
Example in Python:
for count in range(1, 11):
print(count)
Example in Java:
for(int count=1; count<=10; count++){
System.out.println(count);
Console.WriteLine(count)
Next count
Page 21 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Pre-condition Loops
A precondition loop is used when the number of iterations is not known beforehand and is dependent Your notes
on a condition being true
It is also known as an indefinite loop
The loop will continue to execute while the condition is true and will stop once the condition becomes
false
Example in Pseudocode:
INPUT temperature
INPUT temperature
END WHILE
Example in Python:
temperature = float(input("Enter temperature: "))
Example in Java:
Scanner input = new Scanner(System.in);
temperature = input.nextFloat();
Page 22 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Loop
Page 23 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Postcondition Loops
A post-condition loop is used when the loop must execute at least once, even if the condition is false Your notes
from the start
The condition is checked at the end of the loop
Example in Pseudocode:
REPEAT
INPUT guess
UNTIL guess = 42
Example in Python:
Postcondition loops don’t exist in Python and would need to be restructured to a precondition loop
Example in Java:
Scanner input = new Scanner(System.in);
int guess = 0;
do {
guess = input.nextInt();
Console.WriteLine("Enter guess")
guess = Console.ReadLine()
Page 24 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
for i ← 1 to 10
input num
next i
output total
Python example:
total = 0
total += num
print("Total:", total)
Java example:
int total = 0;
total += num;
Page 25 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
For i As Integer = 1 To 10
total += num
Next i
Page 26 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Counting
Counting involves keeping track of the number of times a particular event occurs Your notes
A count variable can be initialised to 0 and then updated within a loop, such as:
Pseudocode example:
count ← 0
for i ← 1 to 10
input num
ount ← count + 1
end if
next i
output count
Python example:
count = 0
if num > 5:
count += 1
print("Count:", count)
Java example:
int count = 0;
if (num > 5) {
Page 27 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
count++;
} Your notes
}
For i As Integer = 1 To 10
count += 1
End If
Next i
Worked example
Write an algorithm using pseudocode that:
Inputs 20 numbers
Outputs how many of these numbers are greater than 50
[3]
FOR x ← 1 TO 20 [1]
INPUT Number
NEXT x
Page 28 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
String Handling
Your notes
String Handling
Strings are a sequence of characters, such as letters, numbers, and symbols
They are used to represent text in a computer program
String handling refers to the various operations that can be performed on strings
Length
The length of a string is the number of characters it contains
In Python, the len() function is used to find the length of a string
In Java, the length() method is used to find the length of a string
In Visual Basic, the Len() function is used to find the length of a string
Substring
A substring is a portion of a string
In Python, the substring can be obtained using the slicing operator [:]
In Java, the substring() method is used to obtain a substring
In Visual Basic, the Mid() function is used to obtain a substring
Upper
The upper() method converts all characters of a string to uppercase
In Python, the upper() method is used to convert a string to uppercase
In Java, the toUpperCase() method is used to convert a string to uppercase
In Visual Basic, the UCase() function is used to convert a string to uppercase
Lower
The lower() method converts all characters of a string to lowercase
In Python, the lower() method is used to convert a string to lowercase
In Java, the toLowerCase() method is used to convert a string to lowercase
In Visual Basic, the LCase() function is used to convert a string to lowercase
Pseudocode example:
string phrase ← "Save my exams"
length ← LENGTH(phrase)
substring ← SUBSTRING(phrase, 5, 2)
upper ← TO_UPPER(phrase)
lower ← TO_LOWER(phrase)
Python example:
Page 29 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
upper = phrase.upper()
lower = phrase.lower()
Java example:
String phrase = "Save my exams";
Page 30 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Worked example
Your notes
The function Length(x) finds the length of a string x. The function substring(x,y,z) finds a substring of x
starting at position y and z characters long. The first character in x is in position 1.
Write pseudocode statements to:
Store the string “Save my exams” in x
Find the length of the string and output it
Extract the word exams from the string and output it
[6]
Z ←5
Exam Tip
Remember that the length of a string is not the same as the index of the last character in the string
Be careful when counting positions in a string, as the first character can be at position zero or one
depending on the programming language
Page 31 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
b←3
c←a+b
d←a-b
e←a*b
f←a/b
g ← a MOD b
h←a^b
i ← a DIV b
Python example:
a=5
b=3
c=a+b
d=a-b
e=a*b
f=a/b
g=a%b
Page 32 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
h = a ** b
i = a // b Your notes
Java example:
int a = 5;
int b = 3;
int c = a + b;
int d = a - b;
int e = a * b;
double f = (double) a / b;
int g = a % b;
int i = a / b;
Dim b As Integer = 3
Dim c As Integer = a + b
Dim d As Integer = a - b
Dim e As Integer = a * b
Dim f As Double = a / b
Dim i As Integer = a \ b
Page 33 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Logical Operators
Equal to (=): Returns true if two values are equal Your notes
Less than (<): Returns true if the first value is less than the second value
Less than or equal to (<=): Returns true if the first value is less than or equal to the second value
Greater than (>): Returns true if the first value is greater than the second value
Greater than or equal to (>=): Returns true if the first value is greater than or equal to the second value
Not equal to (<>): Returns true if two values are not equal
Pseudocode example:
a←5
b←3
c ← (a = b)
d ← (a < b)
e ← (a <= b)
f ← (a > b)
g ← (a >= b)
h ← (a <> b)
Python example:
a=5
b=3
c = (a == b)
d = (a < b)
e = (a <= b)
f = (a > b)
g = (a >= b)
h = (a != b)
Java example:
int a = 5;
Page 34 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
int b = 3;
boolean h = (a != b);
Dim b As Integer = 3
Dim c As Boolean = (a = b)
Page 35 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Boolean Operators
Boolean operators are logical operators that can be used to compare two or more values and return a Your notes
Boolean value (True or False) based on the comparison. There are 3 you need to know:
AND: Returns True if both conditions are True
OR: Returns True if one or both conditions are True
NOT: Returns the opposite of the condition (True if False, False if True)
Boolean Operators in Pseudocode:
IF (condition1 AND condition2) THEN
END IF
END IF
IF NOT(condition) THEN
END IF
if condition1 or condition2:
if not condition:
Page 36 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
if (condition1 || condition2) {
if (!condition) {
End If
End If
End If
Exam Tip
Boolean operators are often used in conditional statements such as if, while, and for loops
Boolean operators can be combined with comparison operators such as == (equal to), != (not
equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to)
Be careful when using the NOT operator, as it can sometimes lead to unexpected results. It is
always a good idea to test your code with different inputs to ensure that it works as expected
Page 37 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Nested Statements
Your notes
Nested Statements
Nested statements involve including one statement within another statement. This can be done with
both selection (if/else) and iteration (for/while) statements
In programming languages like Python, Java, and Visual Basic, nested statements are often indicated
by indenting the inner statement(s) relative to the outer statement(s)
Exam Tip
You will not be required to write more than three levels of nested statements
Page 38 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Nested Selection
Nested selection is an if statement inside an if statement Your notes
If the first if statement is true, it will run the if statement which is nested inside
Otherwise, it will skip to the "else if" or "else" which is part of that if statement
Pseudocode example:
if a > b then
if b > c then
else
else
if a > c then
else
Python example:
if a > b:
if b > c:
else:
else:
if a > c:
else:
Page 39 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Java example:
if (a > b) {
Your notes
if (b > c) {
} else {
} else {
if (a > c) {
} else {
If b > c Then
Else
End If
Else
If a > c Then
Else
Page 40 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Exam Tip
Indentation is key so make sure it's clear in your answer which if statement line is part of which. It's
more clear when you use end if in the appropriate places, too.
Page 41 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Nested Iteration
Nested iteration refers to a loop inside another loop. Your notes
Pseudocode example:
FOR i ← 1 TO 10
FOR j ← 1 TO 5
END FOR
END FOR
Python example:
for i in range(1, 11):
Java example:
for (int i = 1; i <= 10; i++) {
For j As Integer = 1 To 5
Next j
Next i
Page 42 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Exam Tip
Your notes
Nested iteration is useful when we need to perform a task for a specific range of values
It is important to keep track of the number of nested statements
It is important to keep nested statements organized and clear. Use consistent indentation and
avoid going too many levels deep, as this can make the code difficult to read and understand
Page 43 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 44 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Procedures
Procedures are defined using the PROCEDURE keyword in pseudocode, def keyword in Python, Your notes
public in Java and Sub keyword in Visual Basic
Procedures can be called from other parts of the program using their name
Pseudocode example:
PROCEDURE calculate_area(length: INTEGER, width: INTEGER)
END PROCEDURE
Python example:
def calculate_area(length, width):
calculate_area(5,3)
Java example:
public class Main {
static void calculateArea(int length, int width) {
int area = length * width;
System.out.println("The area is " + area);
}
Page 45 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 46 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Functions
Functions are defined using the FUNCTION keyword in pseudocode, def keyword in Python, and Your notes
Function keyword in Visual Basic and Java
Functions return a value using the RETURN keyword in pseudocode, return statement in Python, and
function name in Visual Basic and Java
Functions can be called from other parts of the program using their name, and their return value can be
stored in a variable
Pseudocode example:
FUNCTION calculate_area(length: INTEGER, width: INTEGER)
RETURN area
END PROCEDURE
To output the value returned from the function you would use the following pseudocode:
OUTPUT(calculate_area(5,3))
Python example:
def calculate_area(length, width):
return area
print(calculate_area(5,3))
Java example:
public class Main {
static int calculateArea(int length, int width) {
int area = length * width;
return area;
}
Page 47 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
CalculateArea(5, 3)
Return area
End Sub
Page 48 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
RETURN average
END FUNCTION
total_score ← 0
END PROCEDURE
Python example:
def calculate_average(num1, num2):
return average
total_score = 0
def add_score(score):
global total_score
Page 49 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Java example:
static int totalScore = 0;
Your notes
public static void main(String args[]) {
addScore(10);
return average;
AddScore(10)
Return average
End Function
Page 50 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 51 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Library Routines
Your notes
Library Routines
Library routines are pre-written code that can be used in programs to perform specific tasks.
Using library routines saves time by not having to write code from scratch
Library routines are also tested and proven to work, so errors are less likely
Some commonly used library routines include:
Input/output routines
Maths routines
Libraries can be included in programs by importing them
The specific syntax for importing a library may vary depending on the programming language being
used
It is important to check the documentation for a library to understand its usage and available functions
Maths routines
MOD: a function that returns the remainder when one number is divided by another number
Pseudocode example: x MOD y
Python example: x % y
Java example: x % y
Visual Basic example: x Mod y
DIV: a function that returns the quotient when one number is divided by another number
Pseudocode example: x DIV y
Python example: x // y
Java example: x / y
Visual Basic example: x \ y
ROUND: a function that rounds a number to a specified number of decimal places
Pseudocode example: ROUND(x, n)
Python example: round(x, n)
Java example: Math.round(x * 10^n) / x;
Visual Basic example: Math.Round(x, n)
RANDOM: a function that generates a random number between x and n
Pseudocode example: RANDOM(x,n)
Python example: random.randint(x,n)
Java example: rand.nextInt(x)
Visual Basic example: rand.next(x,n)
Exam Tip
Remember to import or include the appropriate library before using the routines in your code
Page 52 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Maintaining Programs
Your notes
Maintaining Programs
Why is it important to create a maintainable program?
Improve program quality:
A maintainable program is easier to understand and modify, which leads to fewer bugs and better
program quality
Reduce development time and costs:
A maintainable program requires less time and effort to modify, which reduces development time
and costs
Enables collaboration:
A maintainable program makes it easier for multiple developers to work together on the same
project, as it's easier to understand and modify
Increase program lifespan:
A maintainable program is more likely to be updated and maintained over time, which increases its
lifespan and usefulness
Adapt to changing requirements:
A maintainable program is easier to modify to adapt to changing requirements or new features
How do you create a well maintained program?
Use meaningful identifiers:
Identifiers are names given to variables, constants, arrays, procedures and functions
Use descriptive and meaningful identifiers to make your code easier to understand and maintain
Avoid using single letters or abbreviations that may not be clear to others
Use the commenting feature provided by the programming language:
Comments are used to add descriptions to the code that help readers understand what the code
is doing
Use comments to explain the purpose of variables, constants, procedures, functions and any
other parts of the code that may not be immediately clear
Use comments to document any assumptions or limitations of the code
Use procedures and functions:
Procedures and functions are reusable blocks of code that perform specific tasks
Using procedures and functions allows you to modularise your code and make it easier to
understand, debug and maintain
Procedures and functions should have descriptive names that clearly indicate what they do
Relevant and appropriate commenting of syntax:
Commenting of syntax is used to explain the purpose of individual lines or blocks of code within
the program
Page 53 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 54 of 54
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers