程序代写代做代考 CMPSC-132: Programming and Computation II

CMPSC-132: Programming and Computation II

Fall 2018

Lab #14
Due Date: 12/07/2018, 11:59PM

Instructions:

– The work in this lab must be completed alone and must be your own. Do not copy code from online
sources. That is considered plagiarism.

– Use the starter code provided on this CANVAS assignment. Do not change the function names or
given started code on your script

– The file name must be LAB14.py (incorrect name files will get a -1 point deduction)

– A doctest is provided as an example of code functionality. Getting the same result as the
doctest does not guarantee full credit. You are responsible for testing your code with enough

data as possible.

– Each function must return the output (Do not use print in your final submission otherwise, you will
get a -1 pt deduction)

– Do not include test code outside any function in the upload. Remove all your testing code before
uploading your file. Do not include the input() function in your submission.

Goal

[5 pts] Write the function makingSound(n,sound) that takes a positive integer number n and a string

and returns a function that takes in a positive integer number k which will return a list with all

numbers from 0 to k-1 but adding the string sound instead for all the numbers that are divisible by

n.

EXAMPLE:
>>> catSound=makingSound(6, ‘Meow’)

>>> catSound(10)

[‘Meow’, 1, 2, 3, 4, 5, ‘Meow’, 7, 8, 9]

>>> makingSound(6, ‘Meow’)(10)

[‘Meow’, 1, 2, 3, 4, 5, ‘Meow’, 7, 8, 9]

[5 pts] Write the function vectorizing(term) that takes a function to apply and returns a function

that takes in a list aList which will run term on each item in aList and returns a list containing

[term(item 1), term(item 2), … , term(item n)]

EXAMPLE:
def square(x):

return x*x

>>> x=[1,2,3,4,5,6]

>>> vectorizing(square)(x)

[1, 4, 9, 16, 25, 36]

>>> y=[‘Hello’,’world’,[],[8,9,7],[[1],[2],[3]]]

>>> vectorizing(len)(y)

[5, 5, 0, 3, 3]

>>> vectorizing(type)(y)

[, , , , ]

>>> vectorizing(lambda w:w>3)(x)

[False, False, False, True, True, True]

Deliverables:

 Submit your script file named LAB14.py to the Lab14 CANVAS assignment before the
due date