Complete the Function: multiply_list_by()
-
Examine the function multiply_list_by() below and read the docstring. This function takes each element in a list, multiplies it by a specified multiplier, and puts the results in a new list which is returned. For example, calling multiply_list_by(my_list, 10) should return the list [10, 30, 50, 70, 90].
-
Fill in the missing code in multiply_list_by(). Notice that the function contains some missing code that you will need to fill in. These missing pieces are encoded as ___ (i.e., three underscores) on lines 11 & 12. Replace the underscores with code that gets the function to operate correctly.
-
Remember that you want to iterate over each element of the argument alist, and append to the new list the value of that element multiplied by multiplier.
1my_list = [1, 3, 5, 7, 9]
2
3def multiply_list_by(alist, multiplier):
4 """Returns a new list that multiplies each element of alist by the
5 multiplier.
6
7 The new list is the same length as alist, and the n'th element of new_list
8 is equal to multiplier times the n'th element of alist.
9 """
10 new_list = []
11 for elem in ___:
12 new_list.append(___)
13 return new_list