Intro to Python
Python is a high level programming language. The language is designed to be readable and is used across many large tech companies such as YouTube, Google, NASA etc.
You can download Python IDLE (Integrated Development and Learning Environment) from the official Python Website.
Other Python Resources:
Analysis
At Advanced Higher you will be expected to analyse the purpose and functional requirements of a problem.
Purpose, Scope and Boundaries
Purpose: This is a general overview of what the software should do, what is its purpose?
Scope: This is a list of all the deliverables of the software upon completion. This list includes; proposed design, completed software, testing conducted and the results, and an evaluation report.
Boundaries: This is the used to define the limits of the program; what it can and can not do. It will also detail any assumptions made by the developers on the client's behalf regarding the requirements.
Feasibility Study
Feasibility study is conducted to investigate any issues regarding the development of the project and whether the developer should proceed with the project given the investigations outcome.
The feasibility study will look into the following areas;
- Economic
- Time
- Legal
- Technical
Economic Feasibility
Economic feasibility looks into whether the project would be economically viable for the company to proceed with. A Cost-Benefit-Analysis is a systematic process for calculating and comparing benefits and costs of a project.
Ultimately the company/developer will be conducting this analysis to determine whether the project is a sound investment and also to use as a basis to compare future projects.
Time Feasibility
This area looks at whether the project can be developed in a reasonable time and if the desired completion date is also reasonable.
Legal Feasibility
When developing software there are legal implication that can affect whether a project is legally feasible. The proposed software system must comply with current laws relevant to the country the software would operate in.
- GDPR
- Copyright Designs and Patents Act
- Computer Misuse Act
Technical Feasibility
This area looks at whether the current hardware and software capabilities are suitable for the proposed project, and if acceptable performance and implementation be expected.
An example of technical feasibility study would be the rise of mobile phones along with the differing screen sizes/resolutions and hardware.
User Surveys
Design
The Design phase will see you learning about UML class and use case diagrams, Gantt Charts and wireframe designs.
Wireframes
Wireframes are an important part of the design phase. They highlight locations of content such as text, images, videos and sound as well as interactive elements such as buttons, forms and .
At Advanced Higher level you are required to include any validation required, any underlying processes and intended output.

UML Class Diagrams
UML Class Diagrams are used to show the classes of objects required for a system. The UML Class notation consists of 3 parts;
- Class name
- Class instance variables
- Class methods
property |
---|
- address: String - town: String - bedrooms: Integer - description: String - houseValue: Integer |
+ house() + setAddress() + getAddress() + updateBedrooms() |
Looking at the UML diagram above, the class variables have a dash next to them - this indicates that these variables are private and should not be accessed directly. Instead they should only be accessed (retrieved, updated, edited etc) by the methods which are public as denoted by the plus symbol.
So in the example above, if a house in our program had a renovation whereby the owners added an extra bedroom, then to update that house' number of bedrooms we would have to use the method updateBedrooms(). This is called encapsulation.
Inheritance
Inheritance in object oriented programming means to inherit the properties from the super class and pass them into a sub-class. This sub-class is mostly the same as the super class, only it will have a few extra properties and/or methods of its own.
Polymorphism
Just like inheritance, polymorphism is done from a sub-class perspective. However, instead of adding extra properties and/or methods, we are instead making a change to the method inherited from the super class.
In the example above we are overriding the calculateWages() method to calculate the wage of a student differently to that of a regular employee. Since the student won't pay taxes we need a different calculation, but under the same method name.
Implementation
Data Types and Structures
2D Arrays
2D (2 Dimensional) Arrays are simply arrays within an array.
A 1D Array stores multiple pieces of the same kind of information in a single data object, and is created as such;
color_array = ["Red","Blue","Orange","Purple"]
A 2D Array will store arrays inside of a single array.
cars = [["BMW","320d","Red"],["Audi","A3","Black"],["Ford","Fiesta","Silver"]]
If we were to use a for loop to print the contents of the above 2D array we would get the following output;
for i in range(0,len(cars)):
print(cars[i])
>>['BMW', '320d', 'Red']
>>['Audi', 'A3', 'Black']
>>['Ford', 'Fiesta', 'Silver']
2D Arrays are not particularly useful when it comes to storing multiple pieces of information about a subject and then having multiple instances of that subject. You should be comfortable with arrays (creating, adding data, removing data, printing contents) from Higher.
You will be expected to know how to;
- Traverse a 2D Array
- Display contents of a 2D Array
- Read a file into a 2D Array
Linked Lists
Linked Lists is a dynamic data structure that stores items in nodes.
Although arrays can perform the same outcome as linked lists, it is important to know that arrays will make a copy of themselves when the size of the array changes, which has major implications for both memory and processor usage.
A linked list works by having 3 pieces of data; memory address, data, and next pointer.
The memory address is simply where this object is stored in memory, the data is the data being held, and the next pointer is an address of the next node (item) in the linked list. The start of a linked list is called the head, and the last node will point to null.
memory address | |
---|---|
data | next pointer |
Object Oriented Programming
Classes
Before we can create our arrays of objects, or even an object, we must initialise a class. There are 2 ways we can approach setting up the class; 1st is we pass in the variables upon initialisation, 2nd is we initialise empty values then update the values later on. To start we will pass in the values upon initialisation.
#Pass in values during initialisation
class account():
def __init__(self, newAccountNum, newAccountType, newFirstname, newSurname, newPassword, newBalance):
self.accNumber = newAccountNum
self.accType = newAccountType
self.ownerFirstname = newFirstname
self.ownerSurname = newSurname
self.password = newPassword
self.balance = newBalance
#Pass in values post initialisation
class account():
def __init__(self):
self.accNumber = 0
self.accType = ""
self.ownerFirstname = ""
self.ownerSurname = ""
self.password = ""
self.balance = 0.0
This second approach is not recommended; we run the risk of not entering data into an object, but also we are directly accessing the objects variables which should only be accessed via methods. Which further causes issues as now we would need to create a method to update every single variable (There might be scenarios where not every single variable should be updated/changed after initialisation).
Methods
Once we have the class setup with its variables, we now need to add in methods which can access the data to either; add, update or use as part of an output.
class account():
def __init__(self, newAccountNum, newAccountType, newFirstname, newSurname, newPassword):
self.accNumber = newAccountNum
self.accType = newAccountType
self.ownerFirstname = newFirstname
self.ownerSurname = newSurname
self.password = newPassword
self.balance = newBalance
def getBalance():
return self.balance
def changePassword():
oldPW = input("Enter old password:")
newPW = input("Enter new password:")
newPWConfirm = input("Re-enter new password:")
if newPW == newPWConfirm:
self.password = newPWConfirm
print("New password set")
else:
changePassword()
Sub-class
There will be scenarios where the class we created needs to be changed slightly - still all of the original properties and methods, but with some extra. For example, the bank account above, we might have an account that is for the bank staff whereby they will have permissions and access to customers bank details. Here they can make changes to the account information, but regular bank customers should not have access to these methods.
class account():
def __init__(self, newAccountNum, newAccountType, newFirstname, newSurname, newPassword, newBalance):
self.accNumber = newAccountNum
self.accType = newAccountType
self.ownerFirstname = newFirstname
self.ownerSurname = newSurname
self.password = newPassword
self.balance = newBalance
def changeSurname(newSurname):
self.ownerSurname = newSurname
def changePassword():
oldPW = input("Enter old password:")
newPW = input("Enter new password:")
newPWConfirm = input("Re-enter new password:")
if newPW == newPWConfirm:
self.password = newPWConfirm
print("New password set")
else:
changePassword()
class staffAccount():
def __init__(self, newAccountNum, newAccountType, newFirstname, newSurname, newPassword, newStaffID):
account.__init__(newAccountNum, newAccountType, newFirstname, newSurname, newPassword)
self.staffID = newStaffID
def changeAccountType(customerAccNum):
#code to search and find customer account number
#code to change customer account type
def updateCustomersBalance(customerAccNum):
#code to search and find customer account number
#code to update customer balance
In the code above, we have 2 classes; 1st is a super class - a class that any other classes will base themselves off, and 2nd is a sub-class where we are inheriting the properties and methods from the super class, but adding in some extra methods that only this class and subsequent objects should possess.
This is called inheritance.
Database Implementation
Standard Algorithms
At N5 and Higher level we learned about a few standard algorithms; find min, find max, linear search and count occurences. It is wise to still know about these standard algorithms and be able to implement them, but you will also be expected to know and implement 3 new standard algorithms; bubble sort, insertion sort and binary search.
Bubble Sort
A bubble sort is used to order data from smallest to largest or vice versa. It does this by comparing 2 elements with eachother and swapping positions based on the comparison being made.
The process is repeated until the data is in order. The process that are repeated can be broken down into 4 steps.
- Start loop for length of data/array
- Start a seond loop for length of the data/array minus 1 and minus iteration number of the first loop
- Compare the 1st item with the 2nd item
- Swap if the comparison is true
Lets look at an example of a bubble sort in Python;
numbers = [3,6,8,2,3,5,1]
for i in range(len(numbers)):
for j in range(0,len(numbers)-i -1):
if numbers[j] > numbers[j+1]:
temp = numbers[j]
numbers[j] = numbers[j+1]
numbers[j+1] = temp
print(numbers)
Testing
It is important that you test your program for errors and bugs throughout the development process.
However, you will move onto a testing stage whereby you will be testing the code with a range of inputs to ensure that it works as expected. We will use test data and it can be split into 3 categories;
- Normal
- Extreme
- Exceptional
Normal test data is as the name suggests; normal. This is the data that should be entered into the program for it serve its purpose. Let's take an example of a prgram that asks the user for a test score as a percentage. We know that the only acceptable scores in percentage format for a test is 0 to 100. Therefore, 1-99 can be considered normal test data.
Extreme test data is quite simple; for the example above, it would be 0 and 100. Extreme test data is such data that sits on the boundary of acceptable and not acceptable data. 0 and 100 are still valid numbers that can be entered but they are the boundary of what is acceptable and not.
Therefore, Exceptional test data is any data that should not be accepted by the program. Keeping with the example above, we can say that any number that is not 0 to 100 is execeptional. So, numbers like -10 and 125 are not acceptable numbers for a percentage when it comes to a test score.
Errors
Errors will always happen in programming. They are inevitable. That's why it is important to understand the types of errors and therefore, how to go about fixing them.
Syntax Errors
Syntax errors are ones that break the rules of the language you are coding in. There are set rules that must be followed in order for the code to work.
print "Hello"
The print statement is a function and in Python it requires round brackets.
print ("Hello")
The lack of brackets in the example above is considered a syntax error because it will 1. prevent the program from running, and 2. is a mistake whereby we have not followed the rules of the programming language.
Logic Error
A logic error is slightly more difficult to find and fix. It is an error that is caused by improper logic, of which the computer can not follow.
score = 89
if score < 40 and > 100:
print("You have passed")
The above code reads as; if the score is less than 40 and greater than 100, then print the message "you have passed", but a single number cannot be both greater than 100 AND less than 40 at the same time. It is also logically incorrect as the pass percentage is greater than 40 and less than 100, which this if statement does not check correctly.
Execution Error
An execution error is when the code is running but then ecounters a error that causes it to stop working. One such example is the program trying to access the index of an array that doesn't exist.
scores = [78,54,87,95,23]
for i in range(0,6):
print(scores[i])
It might not be immediately obvious, but the array we setup called scores contains 5 scores. The index values for these 5 scores is 0, 1, 2, 3, and 4. We then use a for loop to print the individual array values using the index number to access each position.
However, the loop is set to run from 0 to 6 (which will run 6 times) and there is only 5 items in the array, so when it gets to the 6th loop, it will try to access the 6th position in the array which, as we know, doesn't exist.