Task 1. Explain, critique, comment and debug code (ILO2)
Suppose you have found the following (incomplete) Python code on a scrap of paper inside a textbook
on Data Compression. The Python function is not quite finished and contains some errors.
def e(a)
b = ”
d = ”
for i in range(1,len(a)-1)
if (d==”)
c = 1
elif (a[i]==d)
*** unreadable line of code ***
else
b = b+str(c)+d
c = 1
d = a[i]
b = b+str(c)+d
return(b)
# Test example: input “aaaaabbbbbbbbbbbcaaadd” –> output “5a11b1c3a2d”
(1) Firstly, give a detailed critique of the incomplete Python code given above. Secondly,
implement (in Python) the one unreadable line of code, fix any syntax errors so that the Python
code runs, ensure the code follows good Python coding style, and improve all the variable and
function names. Make sure you give your full critique of the code before fixing anything. Then
provide a corrected version of the code. Do not fix any semantic errors. Be very careful about
the indenting given.
[10 marks]
(2) The given Python function is supposed to encode a given input string (see the test example
provided above).
(a) Add appropriate print statements to your Python code from part (1) to generate (directly
from the code) a clear example illustrating the encode algorithm running in detail. The
level of detail should give commentary and insight into how the code works and what it
actually does. Please provide both code and output in your answer.
(b) Explain the encode task clearly (assuming that the input string does not include any digits)
and then fix any semantic errors so that your Python code actually does solve the encode
task correctly. Consider what the output should be when the input is an empty string.
Please provide both code and output in your answer.
(c) Write a new Python function that will decode the output string from your encode function
in part (2)(b) to return the original input string. Test your encode and decode functions on
a suitable example from the ASCII Art Archive (https://www.asciiart.eu/). Please provide
both code and output in your answer.
(d) Suggest a change to the encode task so that the length of the output string is never longer
than the length of the input string.
[15 marks]
Task 2. Design, build and test (ILO2)
Beetle is a simple dice game for one player. The aim is to collect all the body parts of one Beetle.
Rolling an unbiased six-sided dice, a 1 gives a Beetle body, 2 gives a head, 3 gives an antenna, 4 gives an
eye, 5 gives a mouth, and 6 gives a leg. The player must collect a Beetle body before any other body
parts can be added. The player must collect a Beetle head before any antennae, eyes or mouth can be
added. A complete Beetle consists of one body, one head, two antennae, two eyes, one mouth, and six
legs.
Image from: https://www.alzproducts.co.uk/beetle-game
Before you write any Python code, it is worth playing this game using a pencil, paper and a six-sided
dice (or use https://rolladie.net/).
(1) Implement this dice game as one Python function. Follow the steps and logic you would take in
a physical game. Your code should include enough print statements to generate a clear
nontrivial example illustrating a play of the game, telling the story as the dice is rolled and the
Beetle body parts are assembled. Explain carefully (with evidence) how you have used
“incremental development” while implementing your Python code. Please provide both your
code and the output from one sample run. You must not implement a Python class. Do not
attempt to produce a graphical visualisation. The storytelling should be sufficient to be able to
test your code by looking only at the output it produces. Marks will be given for both the quality
of code and the quality of the storytelling.
[15 marks]
(2) Modify your Python code to add at least three counts that effectively summarise different
aspects of the game, e.g., the total number of dice rolls made. These counts should vary from
run to run and you are encouraged to think creatively. Use these summary counts to compare
the original game descried above with the variant in which the player needs to build a “mutant”
Beetle that has one body but two complete heads. Please provide your updated Python code
for the original game with counts, the Python code for the mutant Beetle, together with output
from one sample run of each. Provide a summary table of counts for the two game versions,
along with a clear and robust conclusion based on your results.
[10 marks]
Task 3. Critically assess, select and apply data science tools (ILO3)
This task involves creating interesting exploratory graphical plots using appropriate Python libraries and
then critically assessing/comparing the capabilities of those plotting libraries.
(1) “Time series” data is a sequence of data points in time order, usually at equally spaced points in
time. Find an interesting univariate (one variable) time series dataset from the Office for
National Statistics (ONS) Time Series Explorer (https://www.ons.gov.uk/timeseriestool). Build
one polished plot of your time series dataset using Python. Also use Python to illustrate one
time series analysis concept such as rolling average, exponential smoothing or finite differences
using your time series dataset. The only Python libraries you may use in this part are numpy
and matplotlib, except that you may use pandas only to load the dataset and convert the
relevant column to a numpy array using pandas.Series.to_numpy(). Please provide both Python
code and any plots produced. Clearly indicate exactly where the dataset comes from.
[10 marks]
(2) Find an existing graphical plot of a dataset in an article on the BBC News website, e.g., by
searching Google Images for “bbc news graph”. Reproduce the graphical plot as closely as you
can using any two of the seaborn, plotly and plotnine Python plotting libraries separately (but
with some help from matplotlib). Comment on how well you are able to achieve this. Focus on
the content of the plot rather than the exact look and aim to make your two plots as similar as
possible. Include the original BBC News image, together with a weblink to the article it is in.
Please provide both your Python code and the plots produced. You must clearly cite and
reference any sources you have used. The graphical plot you select must not consist only of text
and must not be a pie chart.
[10 marks]
(3) Use your experience from parts (1) and (2) to critically assess the Python plotting libraries you
have used in terms of the following criteria: difficulty of coding, adaptability of the code, level
of control over the plot layout or labelling, and quality of the graphical plot produced. Present
your critical assessment in an appropriate table.
[5 marks]
Task 4. Data protection and data ethics (ILO3)
“Arguing that you don’t care about the right to privacy because you have nothing to hide is no different
than saying you don’t care about free speech because you have nothing to say.”
— Edward Snowden (2016)
https://www.businessinsider.com/edward-snowden-privacy-argument-2016-9
“Just as medieval alchemists were convinced a (mythical) philosopher’s stone can transmute lead into
gold, today’s privacy practitioners believe that records containing sensitive individual data can be
‘de-identified’ by removing or modifying [personally identifiable information].”
—.Narayanan and Shmatikov (2010)
The right to privacy is protected by the United Nations 1948 Universal Declaration of Human Rights (see
Article 12). Many individuals believe that privacy can only be maintained by greater control over their
personal information through “informed consent”. Many organisations believe that “anonymisation”
of personal data (data that can be used to identify an individual) allows data to be freely shared while
preserving privacy.
(1) Briefly describe (with small examples) ways in which a dataset can be “anonymised” (or
“pseudonymised”), considering both quantitative and categorical data.
[5 marks]
(2) Briefly describe a recent UK example of “deductive disclosure” (otherwise known as the “jigsaw
effect” or the “mosaic effect”) that had some adverse impact (or had the potential for some
adverse impact) upon people. Critically evaluate how the relevant principles in GDPR and the
UK Government Data Ethics Framework could (or should) have prevented or mitigated this
impact. You must clearly cite and reference any sources you have used.
[10 marks]
(3) In the age of Big Data, discuss to what extent are “anonymisation” and “informed consent”
(both “notice” and “choice”) sufficient to safeguard an individual’s right to privacy. This part
invites you to make and defend a judgement or recommendation.
[10 marks]
Reference
Narayanan, A. and Shmatikov, V. Myths and fallacies of personally identifiable information.
Communications of the ACM, 53(6), 2010. https://dl.acm.org/doi/10.1145/1743546.1743558
I need atleast 15 references in APA Format