预定/报价
Python代写 | COMPS209F Data Structures, Algorithms, and Problem Solving
叶师傅2024-05-27 16:58:30

留学生作业代写do not hesitate to contact me!
WeChat:lovexc60


COMPS209F
Data Structures, Algorithms, and Problem Solving
Preamble
This assignment has replaced the Practical Test (15%) for this presentation of COMPS209F, as
an exceptional measure for the suspension of on-site teaching and learning activities for the
Spring 2020 term.
Submission
All answers should be submitted in files. Each question specifies the files (i.e.the names of the
files) to be submitted. All the files should be combined into a ZIP file. The file name should be
OUID-Surname.zip. For example, if you OUID is 12345678 and your surname is Chan, then
the file name should be 12345678-Chan.zip.
Please submit the ZIP file to the OLE – COMPS209F – Assigment 1
Grading of Programming Exercises
• A program header, containing at least your name, OUID, date, and the purpose of the
program, should be included in every program file. Failure to do so will be penalized.
• Submitted programs that are fail to run may get 0 mark.
• Programs with poor styles such as redundant logic and statements and poor chosen
variable names may be penalized up to 20% of the allocated mark.
• Input validation is not required, unless it is explicitly required by the question.
• Your solution must be coming from your own independent work. Academic
dishonesty will result in severe penalty.
Submission Summary
The following table shows the files that may be submitted. The submitted files will be
computer-processed. Failure to use the correct file names may earn you zero mark. Skeleton
files are provided for most questions for your convenience.
Filename Format Question
q1a.py Python Source Question 1(a)
q1b.py Python Source Question 1(b)
q1c.py Python Source Question 1(c)
q1d.py Python Source Question 1(d)
q1e.py Python Source Question 1(e)
q1f.py Python Source Question 1(f)
q1g.py Python Source Question 1(g)
q1h.py Python Source Question 1(h)
q1i.txt Text File Question 1(i)
q1j.py Python Source Question 1(j)
q2a.py Python Source Question 2(a)
COMPS209F Assignment (Spring 2020)
10:04 AM 4/9/20 3
Question 1 Programming Exercises (76%)
(a) One kilometer is equivalent to 0.621371 miles. Complete a following Python function for
converting a length in kilometers to miles.
def convert2mile(kilometer):
The parameter holds the kilometer to be converted. A similar function convert2inches is
given to you as a reference Submit your solution in q1a.py. [12 marks]
(b) Chris believes that an English word is lucky if it contains the sequence “uck”. Complete a
Python function to return a different value according to the parameter word, which is
assumed always a string.
• Return True if word is lucky
• Return False if word is unlucky
def isLuckyWord(word):
Hint: There is a function in the Python string library for finding the sequence “uck” easily.
Submit your solution in q1b.py. [12 marks]
(c) Complete the following function that takes in a list of numbers.
def isIncreaseList(numlist):
The function should return different values according to the parameter numlist.
• Return True if the numbers in numlist are in strictly increasing (ascending) order.
• Return False if otherwise.
Assume the parameter numlist is always a list of numbers. Some examples are shown below.
Parameter numlist Return value
[1, 2, 3, 4, 5, 6, 7, 8, 9] True (because the numbers are strictly increasing)
[1, 1, 3, 4, 5, 6, 7, 8, 9] False (1 following 1 is not strictly increasing)
[1, 2, 3, 4, 5, 6, 7, 6, 9] False
[1] True
[] True (empty list is considered to be True)
Submit your solution in q1c.py. [8 marks]
(d) Based on your solution for the above part, add parameter checking to the function.
The function should also raise errors according to the following conditions.
• Raise ValueError with the message “None parameter” if numlist is None.
• Raise TypeError with the message “Not a list” if numlist is not a Python list.
Submit your solution in q1d.py. [8 marks]
COMPS209F Assignment (Spring 2020)
10:04 AM 4/9/20 4
(e) A function named rollDices is given to you that returns the sum of rolling two 6-sided
dices. A 6-sided die is a random generator of integers from 1 to 6. So the sum of two 6-sided
dices is a random integer from 2 to 12.
Modify the function parameter list and the function body definition so that the following
function calls will all work as described.
rollDices() Returns the sum of randomly rolling two 6-sided dices
rollDices(8) Returns the sum of randomly rolling two 8-sided dices
rollDices(8, 3) Returns the sum of randomly rolling three 8-sided dices
rollDices(numDices=3) Returns the sum of randomly rolling three 6-sided dices
rollDices(numDices=4, sided=12) Returns the sum of randomly rolling four 12-sided dices
Submit your solution in q1e.py. [6 marks]
(f) Complete the program q1f.py. The program contains a statement that creates a list of 10
random integers in the range from -100 to 100 (inclusive). Add code to filter the list after the
statement so that any number ended with digit 9 and any number between 13 and 31
(inclusive) should be removed from the list.
Your solution must make use of the filter function with a suitable lambda function as the
filter.
Submit your solution in q1f.py. [6 marks]
(g) Complete the following function called strange that returns the sum of a number sequence.
The strange function must be implemented using recursion.
def strange(N):
The function is defined as follows.