109k views
0 votes
The following function is supposed to take in two lists of equal length containing only integer values, and return a new list where each element is the product of the two corresponding elements in the original.

For example, mult_lists ([6,2,4],[3,0,2]) would return [18,0,8].
Fill in the blank in the function with a single line of code, such that the function works as intended.
def mult_lists(left, right):
out = []
for i in range(len(left)):
_____
return out

1 Answer

5 votes

Final answer:

To complete the function, use the line "out.append(left[i] * right[i])" to multiply each pair of corresponding elements in the provided lists and append the results to the output list.

Step-by-step explanation:

The student is asking about how to complete a Python function that takes two lists of equal length containing integer values and returns a new list where each element is the product of the corresponding elements in the two lists.

To fill in the blank in the given function, the line of code should be:

out.append(left[i] * right[i])

This line multiplies the element at the current index i in both the left and right lists and appends the result to the out list. As the loop runs, this operation will be performed for each pair of corresponding elements in the provided lists.

User Mark Segal
by
8.2k points