Question: Produce a Python 3 Jupyter notebook whose contents we describe here. The first cell (a Markdown cell) renders as in the following screenshot. 2 (3

Produce a Python 3 Jupyter notebook whose contents we describe here. The first cell (a Markdown cell) renders as in the following screenshot.

Produce a Python 3 Jupyter notebook whose contents we describe here. The

first cell (a Markdown cell) renders as in the following screenshot. 2(3 pts.). Produce a Python 3 Jupyter notebook whose contents we describehere. The first cell (a Markdown cell) renders as in the following

2 (3 pts.). Produce a Python 3 Jupyter notebook whose contents we describe here. The first cell (a Markdown cell) renders as in the following screenshot. COMP 361 & 651 Data Analytics This is the second part of Assignment 2. Purpose This is to give you familiarity with Jupyter. This cell is followed by another Markdown cell with the following content. Define a function add_reverse() that takes a list of numbers and returns Note that the name of the function is in monospace font. (Use back quotes.) The next cell is a code cell in which you define function add_reverse(). It is passed a list of numbers and returns the list of numbers obtained by adding to each element in the input list the element in the corresponding position of the reversed version of this list. For example, if the input list is [1, 0, 5, 3], then the reversed version is [3, 5, 0, 1), and what is returned by the function is [4, 5, 6, 4]. (Use function reversed () to reverse the list.) The next cell is a Markdown cell whose content is Call add_reverse(), passing the list [2,0,5,1]. Assign the returned value to res. The name of the function, the list, and the name of the variable are all in monospace font. The next cell contains the code accomplishing this and shows the value for res. (Have res on a line by itself at the end of the cell.) This is followed by a Markdown cell with content Find the sum of the values in res. Again, the name of the variable is in monospace font. The last cell is a code cell that finds the sum of the elements of res. Use sum(). 1 (7 pts.). Write a Python script that implements the following functions. Do not have any functions input or output values. All values used by a function should be passed to it as arguments. The value computed by a function should be returned, not output by it. Use the test code shown below (and provided on Blackboard), which satisfies these constraints and outputs the results of all function applications so we can test your implementations. The test code assigns to 1st a list of integers that is used as the running list for testing the functions. When we say below that a function is passed the running list of integers, it could actually be passed any list of integers; it just turns out that the running list is what is passed in our test code. A function sum_threshold() that is passed as its first argument an integer, call it 0, to be used as a threshold and thereafter any number of other integer arguments. It returns the sum of the arguments after 8, calculated from left to right until adding the next would exceed 0; if the sum of all these arguments is less than or equal to 0, then this sum is returned. If only the 0 argument is provided, return 0. Use the arbitrary argument lists technique., with *. (To use the list 1st set at the beginning, you have to unpack it (use a *) when you provide it as an argument. Note that, if you do this, you'll be unpacking the list (with *) when you pass it in and packing the arguments back up (using again a *) in the argument list in the function definition.) The easy way to implement this involves a beak. A function my_slice () that, by default, returns a slice consisting of every second element of the list passed to it. There is a parameter start with default 0 that determines the first index of the slice returned. Parameter step, with default 2, determines the spacing between the elements in the input list that are included in the returned list. (E.g., with step=2, every other element is included; with step = 3, every third element is included.) And parameter length determines the length of the input list (starting at start) that is considered in producing the returned slice. It is not the length of the returned slice. For example, if the input list is 1st = [0, 1, 2, 3, 4, 5, 6], then >>> my_slice (1st, length=6, step=1) [0, 1, 2, 3, 4, 5] >>> my_slice (1st, length=6, step=2) [0, 2, 4] In both cases, the list from index 0 to index 5 is considered since in both cases length=6. In the first case, every element in this part of the list is included in the returned slice whereas, in the second case, only every other element in this part of the list is included. A function with_factors() that is passed the running list of integers (at least in our test code) and a second list of integers and returns a list containing the elements in the running list that have at least one element in the second list as a factor. For example, if the running list is [2, 3, 4, 5, 6, 7, 8, 9] and the list of factors in [2, 3], then the returned list should be [2, 3, 4, 6, 8, 9]. Within the definition of this function, define another function, has_factor(), which is passed two arguments: an integer, x, and the list fcts of factors passed to the top-level function. Then has_factor (x, fcts) returns True if one of the integers in fcts is a factor of x (and otherwise returns False). You can then use filter to apply a lambda expression that uses has_factor () to the running list that was passed in to the function). You will have to convert the filter expression to a list to force it to evaluate A function pairs_factors() that is passed the running list of integers, 1st, and returns a list of pairs (2-element tuples), one pair for each element of 1st. In a given pair, the first element of a pair is the element of 1st itself, call it x, and the second element is the list of those elements of 1st that are factors of x. Note that neither 1 nor x counts as factors of x. Implement this using a nested list comprehension. Note that y is a factor of x if and only if x 8 y == 0 and y isn't in {x, 1}). When performing this mod operation, guard against the case where y is 0, which amounts to division by 0. The following is test code. It is available as test.py on the page where you got this assignment. 1st = [7, 2, 12, 9, 15, 4, 11, 5] print('The sum of the elemenst, left to right, without exceeding the') print('threshold 40 is ', sum_threshold (40, *lst)) print('The same but with a threshold of 70: ', sum_threshold (70, *lst)) print('With an empty list of numbers: ', sum_threshold (50)) r print('my_slice (1st): ', my_slice (1st)) print('my_slice(lst, start=2, step=1): ', my_slice (1st, start=2, step=1)) print('my_slice (1st, start=2, length=5): ', ny_slice (1st, start=2, length=5)) print('my_slice (1st, length=5): ', my_slice (1st, length=5)) print('with_factors (1st, [2, 5]): ', with_factors (1st, [2, 5])) print('pairs_factors (1st): ', pairs_factors (1st)) The following is the output from this test code. The sum of the elemenst, left to right, without exceeding the threshold 40 is 30 The same but with a threshold of 70: 65 With an empty list of numbers: 0 my_slice (1st): [7, 12, 15, 11] my_slice (1st, start=2, step=1): [12, 9, 15, 4, 11, 5] my_slice (1st, start=2, length=5) : [12, 15, 11] my_slice(lst, length=5): [7, 12, 15] with_factors (lst, [2, 5]): [2, 12, 15, 4, 5] pairs_factors (1st): [(7, []), (2, []), (12, [2, 4]), (9, []), (15, [5]), (4, [2]), (11, []), (5, [])) Include docstrings with all you function definitions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!