Question: IN PYTHON def main(): # define the variables needed to test the required functions myvals = [-1, 6, 2, -3, 5, 5, 3, -5, 2,
IN PYTHON
def main(): # define the variables needed to test the required functions myvals = [-1, 6, 2, -3, 5, 5, 3, -5, 2, 5, 3, 3, 10, 5] mymatrix1 = [[50, 3.7, -7, 4], [-8, 9, 310, -1.8], [-120, 7.9, 3.2, 13]
] mymatrix2 = [[19, 3.7, -7], [-8, 9, -1.8], [7.9, 3.2, -11], [4.3, -0.32, 4] ] p1 = [3, 1, -2, -8] p2 = [2, 1.4, 1, -1, 2] x1 = 2.9 x2 = -3.4 # for part a) ans1 = ArraySumEven(myvals) ans2 = ArraySumEven(p1) print('part a) ', ans1, ans2) print() # print a blank line # for part b) ans1 = MatrixProductSmallerThan(mymatrix1, x1) ans2 = MatrixProductSmallerThan(mymatrix2, -2.5) print('part b) ', ans1, ans2) print() # print a blank line
main()
The printed answers are:
part a) 20, -10 part b) 12096.0, -616
You must use comments in your functions, to describe the purpose of your lines of code a) Write a function defined as: def ArraySumEven(vals): vals: an array (list) containing integers or floats return value: the sum of all the even values in the array. Negative values can be ever Note: Use Google to learn how to detect Even or Odd in python b) Write a function defined as: def MatrixProductSmallerThan (A, val): A: a FULL matrix (list of lists) containing integers or floats val: a float or integer. return value: the product of the terms in the matrix that are smaller that val. Note: for this function, 2 is larger than 5,3 is larger than 4, etc
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
