programming
programming
Page 1 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
What is a constant?
A constant is fixed data that during the execution of a program cannot change
A constant can store a variety of different types of data, similar to variables
Pi is an example of a mathematical fixed value that would typically be stored as a constant
What is assignment?
Assignment is the process of storing data in a variable or constant under a descriptive name
Assignment is performed using the '=' symbol
Page 2 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Arithmetic
Operator OCR exam reference Python
Addition + +
Subtraction - -
Multiplication * *
Division / /
Page 3 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Comparison
Operator OCR exam reference Python Your notes
Equal to == ==
Not equal to != !=
Examples
Operator OCR exam reference Python
Page 4 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
What is an input?
An input is a value that is read from an input device and then processed by a computer program
Typical input devices include:
Keyboards - Typing text
Mice - Selecting item, clicking buttons
Sensors - Reading data from sensors such as temperature, pressure or motion
Microphone - Capturing audio, speech recognition
Without inputs, programs are not useful as they can't interact with the outside world and always
produce the same result
What is an output?
An output is a value sent to an output device from a computer program
Typical output devices include:
Monitor - Displaying text, images or graphics
Speaker - Playing audio
Printer - Creating physical copies of documents or images
Page 5 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Python
Worked Example
A cinema calculates ticket prices based on age category
Adult = £13.00
Child = £7.50
The program asks the user to enter their age and calculates the cost of their ticket
A simple algorithm is used
adult = 13.00
child = 7.50
total_cost = adult
else
toal_cost = child
Page 6 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
end if
Page 7 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Programming Constructs
Your notes
What is a Programming Construct?
A programming construct determines the order in which lines of code are executed
They control logic and behaviour of code
There are three core programming constructs:
Sequence
Selection
Iteration
Sequence
What is sequence?
Sequence refers to lines of code which are run one line at a time
The lines of code are run in the order that they written from the first line of code to the last line of code
Sequence is crucial to the flow of a program, any instructions out of sequence can lead to
unexpected behaviour or errors
Example
A simple program to ask a user to input two numbers, number two is subtracted from number one and
the result is outputted
02 Num1 = input()
04 Num2 = input()
Page 8 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
06 print(Result)
Your notes
A simple swap of line 01 and line 02 would lead to an unexpected behaviour, the user would be
prompted to input information without knowing what they should enter
Selection
What is selection?
Selection is when the flow of a program is changed, depending on a set of conditions
The outcome of this condition will then determine which lines or block of code is run next
Selection is used for validation, calculation and making sense of a user's choices
There are two ways to write selection statements:
if... then... else... statements - this is when you test conditions sequentially
case select or switch... statements - this is when you test an expression against multiple possible
constant values (known as cases)
Page 9 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Example
Concept OCR exam reference Python Your notes
print("Correct") print("Correct")
print("Wrong") print("Wrong")
else else:
print("Error") print("Error")
endif
print("Saturday") print("Saturday")
print("Sunday") print("Sunday")
default: case _:
print("Weekday") print("Weekday")
endswitch
If vs select case
Select case can mean less code but it only useful when comparing multiple values of the same
variable
If statements can be more flexible and are generally used more in languages such as Python
Iteration
What is iteration?
Iteration is repeating a line or a block of code using a loop
Iteration can be:
Page 10 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
count controlled - this is when the code is repeated a fixed number of times (e.g. using a for loop)
Your notes
condition controlled - this is when the code is repeated until a condition is met (e.g. using a while loop
or a do while loop)
Page 11 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Examples
Iteration OCR exam reference Python
next x
print(x) print(x)
Page 12 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
print(x) print(x)
This will loop until the user inputs the colour "Red". Check condition is carried
out before entering loop
This will loop until the user inputs the colour "Red". Loop iterates once before a
check is carried out
Worked Example
Page 13 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Tick (✓) one box in each row to identify whether each programming construct has or has not been
used in the program [3]
Your notes
total = 0
for i = 1 to 5
next i
print(total)
Page 14 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Python code
# -----------------------------------------------------------------------
# Arithmetic operators #1
# -----------------------------------------------------------------------
# Get the user to input a number
user_input = int(input("Enter a number: "))
# -----------------------------------------------------------------------
# Arithmetic operators #2
# -----------------------------------------------------------------------
# Get the radius from the user
radius = float(input("Enter the radius of the circle: "))
# ------------------------------------------------------------------------
# Arithmetic operators #3
# ------------------------------------------------------------------------
Page 15 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
if user_answer == correct_answer:
score = score + 1
else:
print("Sorry that's incorrect.")
Page 16 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Python code
# -----------------------------------------------------------
# Common Boolean operators #1
# -----------------------------------------------------------
# Assign a Boolean value to a and b
a = True
b = False
# -----------------------------------------------------------
# Common Boolean operators #2
# -----------------------------------------------------------
Page 17 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
# -----------------------------------------------------------
# Common Boolean operators #3
# -----------------------------------------------------------
# Open the file for reading
file = open("scores.txt","r")
# Set flags to false
end_of_file = False
found = False
score = input("Enter a score: ")
# While it's not the end of the file and the score has not been found
while not end_of_file and not found:
# read the line
scores = file.readline().strip()
# if the line equals the score
if score == str(scores):
found = True
print("Score found")
# if the line is empty
if scores == "":
end_of_file = True
print("Score not found")
file.close()
Page 18 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Data Types
Your notes
Primitive Data Types
What is a data type?
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:
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency
in the program
Data types can be changed within a program, this is called casting
What is casting?
Casting is when you convert one data type to another data type
Example
The following Python program is used to capture a users age to determine if they are old enough to
vote
Page 19 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
04 else:
04 else:
real_value = float(int_value)
Page 20 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
int_value = int(str_value)
str_value = str(int_value)
str_val = str(bool_val)
bool_val = bool(str_value)
Worked Example
Customers booking a holiday can choose between half board or all inclusive and a hotel star rating
between 1 and 5
A typical booking record is shown in the table:
firstName Jacob
lastName Franks
starRating 5
bookingComplete True
State the most appropriate data type for the following fields [2]:
boardType
Page 21 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
starRating
Your notes
Give the name of one field that could be stored as a Boolean data type [1]
Answer
boardType String
starRating Integer
bookingComplete
Page 22 of 22
© 2015-2025 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers