1
The University for business
and the professions
Coursework MOCK Test
Term 3 Elective Module
Module Code Module Title
SMM283 Introduction to Python
Date Time
Division of Marks: 100 marks
Instructions to students: Use Python IDLE (2.7 or above) only to code the
Python solution as a Python file (StudentID.py),
alongside any by-product file(s). Save frequently the
file(s) in a StudentID named folder, and upload the
last version of the saved file(s) to Moodle at the end
of the test.
This paper contains a case study with subparts (a, b, c, d, e, f) and comprises
four pages including the title page
Number of answer books to be provided: N/A
Calculators are permitted: N/A
Dictionaries are NOT permitted
Additional materials or tables to be provided: None
Exam paper can be removed from the exam room: No
2
CASE STUDY:
You have just received a positive response from Barclays on a recent graduate
‘Financial Analyst’ role you had applied for and you are invited to a job interview. The
job specification includes, among other things, knowledge of Python at introductory
level, but with the prospect of further training within the organization. If successful you
will work in a recently re-organized asset pricing department and if you were to be
successful, you’d work as part of a team dealing with financial analysis and asset
pricing that also involves computational work. Your prospective employer has
prepared a three part trial-test for you as part of the interview, entirely based on
introductory Python programming.
You are tested in good modular programming skills and practice by designing
several functional-cohesive modules to the specification provided. The interviewer
has supplied you with the general instructions in pseudo-code format of a program
master control function called main and you’d need to convert them to Python code
and together with the user-defined functions, demonstrate that you truly understand
not only modular design, but that you show awareness of module cohesion, module
coupling and general good programming practice.
REQUIRED:
Create and test Python functions based on the specifications in sections (a), (b), (c),
(d), (f).
(a)
def mean(x = []): receives an array (or list) of real numbers. It computes and
returns the average based on the formula:
(10 marks)
(b)
def pmean(p = [], x = []): receives two arrays (or lists) of real numbers. It
computes and returns the probabilistic average based on the following:
n
px = p
i
x
i
i=1
3
i
(10 marks)
(c)
def var(x = []): that receives an array (or list) of real numbers. It computes the
variance, in accordance to the formula:
(15 marks)
(d)
def pvar(x = [], p = []): receives an array (or list) of real numbers. It
computes the probabilistic variance given by the formula:
p var =
i=1
p (x − x)
2
(15 marks)
(e)
def transpose(m =[[]]): receives a two dimensional array (or 2d list),
representing a matrix of real numbers and swaps rows with columns. The operation
is illustrated below:
(20 marks)
(f)
Test the functions by coding a program control master user-defined function main
based on the following instructions:
1. Define the x variable as a one dimensional array (or list).
2. Define the p variable as a one dimensional array (or list).
3. Define the m variable as a two dimensional array (or list).
n
i
4
4. Prompt the user for data and initialize the variables by reading from the keyboard
5. Call the functions.
6. Print the results in a formatted matter.
Validate the data using loops and any appropriate build-in function, thus making sure
that only numeric data is read in the program and that exceptions are addressed in
an effective manner.
You are expected to produce the file “StudentID.py”. The program must run in order
to be marked.
(30 marks)
END OF EXAMINATION