程序代写案例-CMT309

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Cardiff School of Computer Science and Informatics
Coursework Assessment Pro-forma

Module Code: CMT309
Module Title: Computational Data Science
Lecturer: Dr. Matthias Treder, Dr. Luis Espinosa-Anke
Assessment Title: CMT309 Programming Exercises
Assessment Number: 1
Date set: 27-11-2020
Submission date and time: 29-01-2021 at 9:30am
Return date: before 26-02-2021

This assignment is worth 30% of the total marks available for this module. If coursework is
submitted late (and where there are no extenuating circumstances):

1 - If the assessment is submitted no later than 24 hours after the deadline, the
mark for the assessment will be capped at the minimum pass mark;
2 - If the assessment is submitted more than 24 hours after the deadline, a mark
of 0 will be given for the assessment.

Your submission must include the official Coursework Submission Cover sheet, which can
be found here:

https://docs.cs.cf.ac.uk/downloads/coursework/Coversheet.pdf


Submission Instructions

Your coursework should be submitted via Learning Central by the above deadline. You have
to upload the following files:

Description Type Name
Cover sheet Compulsory One PDF (.pdf) file Student_number.pdf
Your solution to question 1 Compulsory One Python (.py) file Q1.py
Your solution to question 2 Compulsory One Python (.py) file Q2.py
Your solution to question 3 Compulsory One Python (.py) file Q3.py

For the filename of the Cover Sheet, replace ‘Student_number’ by your student number, e.g.
“C1234567890.pdf”. Make sure to include your student number as a comment in all of the
Python files! Any deviation from the submission instructions (including the number and types
of files submitted) may result in a reduction of marks for the assessment or question part.




You can submit multiple times on Learning Central. ONLY files contained in the last attempt
will be marked, so make sure that you upload all files in the last attempt.

Staff reserve the right to invite students to a meeting to discuss the Coursework
submissions.

Testbed

The testbed is a website you can use to upload your implementations of the questions. It
checks your implementations against the correct solutions for a number of testcases. You use
the testbed to make sure that:

- Your function does not crash, that is, there is no Python errors when trying to run the
function.
- Compare the results of the testcases to your results.

For Q1 and Q3, passing all the testcases in the testbed does not assure that you will get full
marks. We will use additional testcases (not disclosed) to test your functions. For Q2, all the
testcases are shown in the question. How to use the testbed:

- Using your browser, navigate to testbed.cs.cf.ac.uk.
- On the website, choose as module CMT309 and enter your credentials to log on.
- Upload your file (Q1.py, Q2.py, or Q3.py) to the testbed and press run. Your code
will be executed for a number of testcases specified in the questions. If any errors
occur, you need to correct your code.
- You can upload and test your files as many times as you want. It is not recorded and
will not affect the mark.

IMPORTANT: You must make sure that your file executes and does not crash before
submitting to Learning Central. Any function that crashes or does not execute will receive 0
marks on the respective (sub)question. Note that the testbed is only provided for your
convenience. You still need to submit your function to Learning Central.
Assignment

Start by downloading the following files from Learning Central:

• Q1.py
• Q2.py
• Proper_nouns.txt
• Q3.py

Then answer the following questions. You can use any Python expression or package that was
used in the lectures and practical sessions. Additional packages are not allowed unless
instructed in the question.


Question 3 – Function renamer (Total 30 Marks)

You are working on a large-scale software project involving thousands of different Python
files. The files have been written by different programmers and the naming of functions is
somewhat inconsistent. You receive a new directive stating that the function names all have
to be in camel case. In camel case, function names consisting of multiple words have a
capital letter in each word and most underscores are removed. For instance, def
MyArithmeticCalculator is in camel case but def
my_arithmetic_calculator is not in camel case.
You want to write a Python program that automatically processes Python code and renames
the function names instead of doing it by hand. The instruction states that:
1. All functions names need to be changed to camel case. E.g. a
function calculate_speed_of_vehicle needs to be renamed
to CalculateSpeedOfVehicle.
2. If the function has one or more leading '_' (underscores) they need to be preserved.
All other underscores need to be removed. E.g. a function __calc_size is renamed
to __CalcSize.
3. If the function is already in camel case, you do not need to change it but it still needs
to appear in the dictionary d specified below.
4. You can assume that there will be no name clashes. That is, a given function name
which is not in camel case will not already appear in camel case elsewhere. E.g. if
there is a function print_all_strings then there is no
function PrintAllStrings elsewhere in the code.
5. Tip: You can use regular expressions to find the function names.
To implement this, write a function function_renamer(code) that takes as input a
string code that represents the Python code. It is typically a multi-line Python string. Your
function needs to return the tuple (d, newcode):
• d is a nested dictionary where each key corresponds to the original function name.
The value is a nested dictionary that has the following items:
o hash: hash code of the original function name (tip: use
Python's hash function)
o camelcase: camel case version of original function name
o allcaps: all caps version of original function name
• newcode is a string containing the code wherein all function names have been
renamed by their camel case versions. Note that you need to change the function
name and also all other locations where the function name is used (e.g. function calls).
You should not change anything else in the code (e.g. the contents of any strings).
To clarify this, a few examples are given next.
Example 1:
Assume your input code is the multi-line string
def add_two_numbers(a, b):
return a + b

print(add_two_numbers(10, 20))
After processing it with your function, the code should be changed to
def AddTwoNumbers(a, b):
return a + b

print(AddTwoNumbers(10, 20))
The nested dictionary is given by
d = {'add_two_numbers':
{'hash':-9214996652071026704,
'camelcase':'AddTwoNumbers',
'allcaps':'ADD_TWO_NUMBERS'}
}
Example 2:
Assume your input code is the multi-line string
def _major_split(*args):
return (args[:2], args[2:])

def CheckTruth(t = True):
print('t is', t)
return _major_split([t]*10)

x, y = _major_split((10, 20, 30, 40, 50))
CheckTruth(len(x) == 10)
After processing it with your function, the code should be changed to
def _MajorSplit(*args):
return (args[:2], args[2:])

def CheckTruth(t = True):
print('t is', t)
return _MajorSplit([t]*10)

x, y = _MajorSplit((10, 20, 30, 40, 50))
CheckTruth(len(x) == 10)




The nested dictionary is given by
d = {'CheckTruth':
{'hash':-6410081306665365595,
'camelcase':'CheckTruth',
'allcaps':'CHECKTRUTH'},
'_major_split':
{'hash':484498917506710667,
'camelcase':'_MajorSplit',
'allcaps':'_MAJOR_SPLIT'}
}

Testbed: If you run function_renamer in the testbed, the following testcases will be tested:
- Example 1 (see above)
- Example 2 (see above)


As a starting point, use Q3.py from Learning Central. Do not rename the file or the function.

Learning Outcomes Assessed

• Use the Python programming language to complete a range of programming task
• Demonstrate familiarity with programming concepts and data structures
• Use code to extract, store and analyse textual and numeric data
Criteria for assessment

Credit will be awarded against the following criteria. The score in each implemented function
is judged by its functionality. For all questions, the functions you have implemented will be
tested against different test cases to judge their functionality. Additionally, quality will be
assessed. Please use the testbed to double check your question after you change it and before
you submit it in Learning Central: Any function that crashes or does not execute will receive
0 marks on the respective (sub)question.
The below table explains the criteria.


Q1,
Q2, Q3
Mark Functionality (80%) Quality (20%)
Distinction
(70-100%)
Fully working application that demonstrates an
excellent understanding of the assignment
problem using relevant python approach

Excellent documentation
with usage of
__docstring__ and
comments
Merit
(60-69%)
All required functionality is met, and the
application are working probably with some
minors’ errors
Good documentation
with minor missing of
comments
Pass
(50-59%)
Some of the functionality developed with and
incorrect output major errors
Fair documentation
Fail
(0-50%)
Faulty application with wrong implementation
and wrong output
No comments or
documentation at all


Feedback and suggestion for future learning

Feedback on your coursework will address the above criteria. Feedback and marks will be
returned within 4 weeks of your submission date via Learning Central. In case you require
further details, you are welcome to schedule a one-to-one meeting. Feedback from this
assignment will be useful for next year’s version of this module as well as the Data Science
Foundations and Statistical Programming modules.

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468