Python代写 | COMPS258 Computer Programming and Problem Solving Assignment 4


Question 1 Programming (56%)
Specific Requirements
Data Validation The range of the input from the user and parameter values should be checked to avoid
causing your program to crash. This includes checking the range and see if the value
making sense and not causing an execution error.
For example, the height of a square should be checked against negative value (which
does not make sense) (which would cause the program to crash).
You need not deal with the cases that have been assumed in the question itself.

(a) You are given that contains three mystery functions, namely funcA, funcB, and funcC,
that process a Python list.
Evaluate the scalability of the three functions empirically, based on the time taken to process
lists of sizes 500, 1000, 2000 and 4000. Refer to Activity 6.19 for how to use the timeit third
party module. [12 marks]
• Complete the program The program should be executed once to generate the
time taken for all the cases in the table below that summarizes the time taken for
processing lists of various sizes by the three functions. The time measurements
should be in seconds down to 4 decimal places. Fill in the results in q1a.txt.
List Size 500 1000 2000 4000

• From the time measurements, write down the performance of funcA and funcB in
Big-O notation. Put your answer in q1a.txt.
• Write down and explain which of funcA and funcB has better scalability. Put your
answer in q1a.txt.
• Make reference to Tables 6.16 and 6.17. From the time measurements of funcC,
compare the performance of funcC (better or worse) to Linear time and Quadratic
time? Suggest the performance of funcC in Big-O notation. Put your answer in
Submit and q1a.txt. [12 marks]

(b) Make sure you have studied Activity 7.7, which is an application of the data structure of stack.
The function checkBalancedSymbols(exp) is given to you in Make the following
enhancements to the function.
• The current implementation considers the square braces and the round braces.
Include the checking on the curly braces, which are ‘{‘ and ‘}’.
• In Python anything after the hash symbol ‘#’ on the same line is ignores. Similarly, the
function should consider the first ‘#’ as the end of the expression.
Some examples are given below.
The expressions (exp) Return value
[1+(2-3)] True

{2 + [1+(2-3)] False
{2 + [1+(2-3)]} # ignored[[[ True
{2 + [1+(2-3)]} [[[ False

Submit [8 marks]

(c) Write a complete Python program that reads in data from a CSV file about major cities mainly
in North America and South America, and then prints out the following findings.
• The name and population of top 5 cities in Mexico with highest population (start from
• The number of cities with population over 5,000,000 in the southern hemisphere (that
is, with negative latitude)
The CSV file contains lines of data, and each line (except the first line which is a header)
contains a comma-separated list of information of a city. The information items include a city’s
name (CITYNAME), latitude (LAT), longitude (LONG), country (COUNTRY), code
(CCODE), population (POP), and status (STATUS).
The program should first ask for the name of the CSV file. Then the program should print the
findings with suitable output decoration. Error handling is needed for data input from the file.
Submit [12 marks]

Complete the following function that returns the number of spaces in the given string
parameter str from the index of startindex to the end of the string. You should use

def countSpaces(str, startindex):

Submit [6 marks]



本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail:  微信:itcsdx