# Fill in the missing parts in the following code. # It should compute the same result as map(lambda x: n*x, L).
def multAll(n, L):
'''Assuming n is a number and L is a list of numbers,
make a list by multiplying each element of L by n.
For example, multAll(3,[3,5,7,9]) is [9,15,21,27].'''
if L==[]:
return None # TO-DO replace None
else:
return None # TO-DO replace None
Python code pasted below.
#Function definition
def multAll(n,L):
if L==[]:
#returns list if list is empty
return L
else:
#list comprehension
return [x*n for x in L]
#main progarm
#function calling - Test case 1
print(multAll(3,[3,5,7,9]))
#function calling - Test case 2
print(multAll(3,[]))
Python code in IDLE pasted below for better understanding
of the indent.
Output Screen
Get Answers For Free
Most questions answered within 1 hours.