0% found this document useful (0 votes)
3 views8 pages

Procedural Programming Guide

This study guide covers procedural programming concepts for OCR A Level Computer Science, focusing on OCR ERL pseudocode and its Python equivalents. It includes topics such as comments, variables, data types, input/output, operators, selection, iteration, string handling, subroutines, arrays, and file handling. The guide emphasizes the differences and similarities between OCR ERL and Python syntax to aid in understanding and application during exams.

Uploaded by

huzefa.rash
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)
3 views8 pages

Procedural Programming Guide

This study guide covers procedural programming concepts for OCR A Level Computer Science, focusing on OCR ERL pseudocode and its Python equivalents. It includes topics such as comments, variables, data types, input/output, operators, selection, iteration, string handling, subroutines, arrays, and file handling. The guide emphasizes the differences and similarities between OCR ERL and Python syntax to aid in understanding and application during exams.

Uploaded by

huzefa.rash
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

Procedural

Programming Study Guide


OCR A Level Computer Science • OCR ERL Pseudocode & Python • No OOP
Each section shows the OCR ERL pseudocode alongside the Python equivalent. You must be able to READ OCR
ERL in the exam, and WRITE in Python (or another high-level language).

1. Comments
A comment is not executed when the program runs. It describes what code does and is especially helpful
when working in teams.

OCR ERL (Pseudocode) Python

// This is a comment # This is a comment


// Comments explain your code # Comments explain your code

2. Variables & Data Types


A variable is declared the first time a value is assigned. It takes the data type of the value given.
Variables inside a subroutine are local. Use global to make a variable accessible everywhere.

OCR ERL (Pseudocode) Python

name = "Alice" // string name = "Alice" # string


age = 17 // integer age = 17 # integer
price = 3.99 // real/float price = 3.99 # float
passed = True // boolean passed = True # boolean
global userID = 5 // global variable # use 'global' keyword inside functions

Data Type Description Example

Text — letters, numbers, symbols. Needs


String "Hello" / "A123"
speech marks.

Integer Whole number. No speech marks. 42 / -7

Real/Float Decimal number. No speech marks. 3.14 / -0.5

Boolean True or False only. Capital letter required. True / False

3. Input & Casting


OCR ERL does not require casting on input. Python always receives input as a string — cast it if you
need to perform calculations.

OCR ERL (Pseudocode) Python


name = input("Enter name: ") name = input("Enter name: ")
age = input("Enter age: ") age = int(input("Enter age: "))
// OCR treats age as a number price = float(input("Enter price: "))
automatically

Function Converts to Example

int(x) Integer int("17") → 17

float(x) Decimal float("3.14") → 3.14

str(x) String str(42) → "42"

4. Output (print)
The print command outputs content to the screen. Use + to concatenate (join) strings. In Python,
commas can also join values but add automatic spacing.

OCR ERL (Pseudocode) Python

print("Hello World") print("Hello World")


print("Name: " + name) print("Name: " + name)
print("Age: " + str(age)) print("Age:", age) # comma adds space

5. Operators
Comparison Operators:
Operator Meaning

== Equal to (double equals — NOT single =)

!= Not equal to

< Less than

<= Less than or equal to

> Greater than

>= Greater than or equal to

Arithmetic Operators (same in OCR ERL and Python):


Operator Meaning Example

+ Addition 3+5=8

- Subtraction 3 - 5 = -2

* Multiplication 3 * 5 = 15

/ Division 3 / 5 = 0.6

MOD / % Modulus — remainder 20 MOD 3 = 2 / 20 % 3 = 2


Integer division — whole number
DIV / // 17 DIV 5 = 3 / 17 // 5 = 3
only

^ / ** Exponentiation — power of 5 ^ 3 = 125 / 5 ** 3 = 125

Logical (Boolean) Operators:


OCR ERL (Pseudocode) Python

if username == "admin" AND password == if username == "admin" and password ==


"1234" then "1234":
if answer == "Japan" OR answer == if answer == "Japan" or answer ==
"[Link]" then "[Link]":
if NOT guess == "yellow" then if not guess == "yellow":

Note: Even if using the same variable, you must write it out again — e.g. answer == "Japan" OR answer ==
"[Link]" not just OR "[Link]".

6. Selection (if / elseif / switch)


OCR uses then and endif. Python uses a colon and indentation (no endif needed).
if / elseif / else:
OCR ERL (Pseudocode) Python

if score >= 70 then if score >= 70:


print("Distinction") print("Distinction")
elseif score >= 50 then elif score >= 50:
print("Pass") print("Pass")
else else:
print("Fail") print("Fail")
endif

switch / case (Python uses match / case):


OCR ERL (Pseudocode) Python

planet = input("Enter planet: ") planet = input("Enter planet: ")


switch planet: match planet:
case "Mars": case "Mars":
print("Red planet") print("Red planet")
case "Venus": case "Venus":
print("Hottest planet") print("Hottest planet")
default: case _:
print("Unknown planet") print("Unknown planet")
endswitch

Nested if — an if inside another if:


OCR ERL (Pseudocode) Python

if num1 > 10 then if num1 > 10:


num2 = input("Enter num2: ") num2 = int(input("Enter num2: "))
if num2 > 10 then if num2 > 10:
print("Both over 10") print("Both over 10")
endif
endif
7. Iteration (Loops)
for loop — count-controlled:
OCR ERL is inclusive (1 to 10 gives 1,2…10). Python range() is exclusive (range(1,10) gives 1,2…9)
so use range(1, 11) to reach 10.

OCR ERL (Pseudocode) Python

for i = 1 to 10 for i in range(1, 11):


print(i) print(i)
next i
# prints 1 2 3 4 5 6 7 8 9 10
// prints 1 2 3 4 5 6 7 8 9 10

while loop — condition-controlled (checks condition BEFORE):


OCR ERL (Pseudocode) Python

answer = "" answer = ""


while answer != "Nairobi" while answer != "Nairobi":
answer = input("Capital of Kenya? ") answer = input("Capital of Kenya? ")
endwhile print("Correct!")
print("Correct!")

do…until loop — condition-controlled (checks condition AFTER — always runs at least once):
OCR ERL (Pseudocode) Python

do # Python has no do..until


answer = input("Capital of Kenya? ") # Use a while True loop instead:
until answer == "Nairobi" while True:
print("Correct!") answer = input("Capital of Kenya? ")
if answer == "Nairobi":
break
print("Correct!")

Nested loops — inner loop completes fully each time outer loop runs once:
OCR ERL (Pseudocode) Python

for i = 1 to 3 for i in range(1, 4):


for j = 1 to 3 for j in range(1, 4):
print(str(i) + "," + str(j)) print(str(i) + "," + str(j))
next j
next i

8. String Handling
Strings are 0-indexed — the first character is at position 0.
Length:
OCR ERL (Pseudocode) Python

subject = "Further Maths" subject = "Further Maths"


print([Link]) print(len(subject))
// outputs: 13 (space counts) # outputs: 13

Substring / Slicing (0-indexed):


OCR ERL (Pseudocode) Python

text = "Computer Science" text = "Computer Science"


print([Link](3, 3)) print(text[3:6])
// start at index 3, take 3 chars # start at index 3, stop BEFORE 6
// outputs: put # outputs: put

Key difference: OCR second argument = number of characters. Python second argument = index to stop before.
Concatenation (joining strings):
OCR ERL (Pseudocode) Python

first = "Ada" first = "Ada"


last = "Lovelace" last = "Lovelace"
print(first + " " + last) print(first + " " + last)
// outputs: Ada Lovelace # or: print(first, last) # comma adds
space

9. Subroutines — Procedures & Functions


A subroutine must be called to run. A procedure does not return a value. A function uses return to
send a value back. Python uses def for both.

Term Meaning

Parameter The variable in the subroutine definition that receives a value.

Argument The actual value or variable passed in when the subroutine is called.

Procedure (no return value):


OCR ERL (Pseudocode) Python

procedure addition(num1, num2) def addition(num1, num2):


total = num1 + num2 total = num1 + num2
print(total) print(total)
endprocedure
addition(5, 3) # outputs: 8
addition(5, 3) // outputs: 8

Function (returns a value):


OCR ERL (Pseudocode) Python

function division(a, b) def division(a, b):


return a / b return a / b
endfunction
print(division(10, 4)) # 2.5
print(division(10, 4)) // 2.5 answer = division(10, 4)
answer = division(10, 4) print(answer) # 2.5
print(answer) // 2.5

10. Arrays (OCR ERL) & Lists (Python)


Arrays hold elements of the same data type and have a fixed size (static). Python uses lists instead —
lists are dynamic and can mix data types. Both are 0-indexed.
Declaring and accessing a 1D array / list:
OCR ERL (Pseudocode) Python

array names[4] names = ["Ahmad", "Ben",


names[0] = "Ahmad" "Catherine", "Dana"]
names[1] = "Ben" print(names[2]) # Catherine
names[2] = "Catherine"
names[3] = "Dana" # Change element:
print(names[2]) // Catherine names[1] = "Beth"

Looping through a 1D array:


OCR ERL (Pseudocode) Python

// Method 1 — using index: # Method 1 — using index:


for i = 0 to 3 for i in range(len(names)):
print(names[i]) print(names[i])
next i
# Method 2 — for each item:
// Method 2 — for each item: for name in names:
for name in names print(name)
print(name)
next name

Searching an array for a match:


OCR ERL (Pseudocode) Python

for i = 0 to 3 for i in range(len(names)):


if names[i] == "Dana" then if names[i] == "Dana":
print("Found at index " + str(i)) print("Found at index", i)
endif
next i

2D Array — rows and columns:


OCR ERL (Pseudocode) Python

array numbers[4, 6] numbers = [[56,12,93,45,71,16],


numbers[0,0] = 56 [34,27,88,63,19,51],
numbers[2,4] = 50 [47,36,79,11,50,82]]
print(numbers[2,4]) // 50 print(numbers[2][4]) # 50

// Print row 0: # Print row 0:


for i = 0 to 5 for i in range(6):
print(numbers[0,i]) print(numbers[0][i])
next i

11. File Handling


A file must be opened before use and closed after. Python uses open modes: r (read), w
(write/overwrite), a (append).
Writing to a file:
OCR ERL (Pseudocode) Python
myFile = openWrite("[Link]") myFile = open("[Link]", "w")
[Link]("Hello World") [Link]("Hello World\n")
[Link]() [Link]()

Reading from a file (line by line):


OCR ERL (Pseudocode) Python

myFile = openRead("[Link]") myFile = open("[Link]", "r")


while NOT [Link]() for line in myFile:
print([Link]()) print(line)
endwhile [Link]()
[Link]()
# Python has no endOfFile() method

OCR ERL Python equivalent

openWrite("[Link]") open("[Link]", "w")

openRead("[Link]") open("[Link]", "r")

[Link](text) [Link](text + "\n")

[Link]() [Link]()

[Link]() No direct equivalent — use for loop

[Link]() [Link]()

12. Quick Reference — OCR ERL vs Python at a Glance


Topic OCR ERL Python
Comment // text # text

Variable x = 5 x = 5

Global global x = 5 global x (inside function)

Input x = input("prompt") x = input("prompt")

Cast int/float/str(x) int/float/str(x)

Output print(value) print(value)

Modulus x MOD y x % y

Int division x DIV y x // y

Power x ^ y x ** y

if if cond then ... endif if cond:

elseif elseif cond then elif cond:

switch switch var: case x: match var: case x:

for loop for i=1 to 10 (inclusive) range(1,11) (exclusive)

while while cond endwhile while cond:

do..until do until cond while True: ... break

Length [Link] len(str)

Substring [Link](start,len) str[start : start+len]

Array array arr[n] arr[0]=val arr = [val, val, ...]


2D Array arr[row, col] arr[row][col]

Function function f(p) return x endfunction def f(p): return x

Procedure procedure p(x) endprocedure def p(x):

Write file openWrite / writeLine open("f","w") / write

Read file openRead / readLine open("f","r") / readline

Based on CSNewbs OCR A Level Computer Science video • Procedural Programming • OOP covered in a separate guide

You might also like