Faculty of Social Sciences School of Mathematical Sciences
Course: MATH6005-Introduction to Python and MATH6181-Python & Forecasting Semester: 2021:2022
Instructor:
Final Assignment: Part 1 (week 6)
Copyright By PowCoder代写 加微信 powcoder
Rules for the Final Assignment: Part 1 (week 6) solution
• You will upload, on Blackboard, one single file.
• The file name, with all functions, must be in the format:
• All functions must follow the prototypes, i.e., they must have the name specified, have the input(s) set, and output the variables in the order specified in the prototypes.
• No partial credit will be given if the function is not working correctly, i.e., due to syntax error, neglect to follow the prototype, etc..
• Only the functions must be in the upload file; any auxiliary or debugging code must be removed of the upload file.
• Please include comments in your code to explain how it works. Fail to comment on your code will result in 10 points reduction on your final assignment mark.
• You can use any buil-in function from Python.
• The solution must have only functions. Do not define any function within another function.
• A template solution file is available on Blackboard.
March 8, 2022
Faculty of Social Sciences School of Mathematical Sciences
TASK 1 (30%)
White a function, using the prototype provided, reads a TXT file, (the TXT file name is book.txt), and
• Finds the letter with the highest and lowest occurrence in the file.
• The function should not differentiate between upper and lower case.
• The function should output four variables: letter_highest, freq_highest, letter_lowest, freq_lowest
• The function must use the input variable file_name to read the CSV file, inside of the function.
Function prototype
def lettersFrequency(file_name): ’’’
function description ’’’
letter_highest = ’0’
freq_highest letter_lowest freq_lowest
return letter_highest , freq_highest , letter_lowest , freq_lowest
Please, the debugging/testing code must not be in your solution file that will be uploaded on Blackboard.
Faculty of Social Sciences School of Mathematical Sciences
TASK 2 (30%)
You are given a spending sheet in a CSV file, (the CSV file name is expenses_by_client.csv), including (name of users, data, spending). User names are unique. Your task is to
• Find the total and mean of spending of each user, then return the user’s name, who has the smallest mean, and the user’s name who spends the most mean in the whole data.
• Find the day when users spend the least. It should be one day for the whole data set.
• Find the users’ name that have the same total of spending if there is any (if not, return “None”).
• The function must use the input variable file_name to read the CSV file, inside of the function.
Your function must follow the prototype below:
Function prototype
Please, the debugging/testing code must not be in your solution file that will be uploaded on Blackboard.
def spendings(file_name): ’’’
function description ’’’
return name_smallest , name_most , day_least , names
Faculty of Social Sciences School of Mathematical Sciences
Task 3 (40%)
You need to calculate the area of an irregular polygon. The polygon is defined by counterclockwise sequence of points (coordinates) Pi = (xi, yi), i = 1, · · · , n. The area can be determined by
A = (xny1 − x1yn) + 22
(xiyi+1 − xi+1yi) i=1
You are given a CSV file, (the CSV file name is map.csv), with the coordinates. Fig.1 shows a draft of the map represented by the coordinates.
• Using the prototype provided, write a function that calculates and returns the area.
• Using the prototype provided, write a function that minimises the area by removing one vertex (point). The function must return the point that minimises the area and the minimal area value.
• The functions must use the input variable file_name to read the CSV file, inside of the functions.
Function prototypes
def area(file_name): ’’’
function description ’’’
total_area = 0
return total_area
def area_minimal(file_name): ’’’
function description ’’’
minimal_area = 0 point_min = [0,0]
return point_min , minimal_area
Please, the debugging/testing code must not be in your solution file that will be uploaded on Blackboard.
Faculty of Social Sciences School of Mathematical Sciences
Figure 1: Map
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com