7143CEM Programming for Data Science

Need Solution - Download from here

7143CEM Assignment Help

Programming for Data Science Assignment help

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 (b==”)
c = 1
elif (a[i]==d)
*** unreadable line of code ***
b = b+str(c)+d
c = 1
d = a[i]
b = b+str(c)+d
# Test example: input “aaaaabbbbbbbbbbbcdd” –> output “5a11b1c2d”

(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 code 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 ratio of the length of the input string to the length of the output string could be decreased in some cases. Make the corresponding changes to your encode and decode functions and demonstrate the effect on a suitable example. Please provide both code and output in your answer.

By |2023-02-09T05:52:02+00:00February 9th, 2023|Categories: computer science|Tags: |0 Comments

Leave A Comment