Computer Science, asked by mirandacarolyn, 7 months ago

write the function:
def addLists(a,b):

The function addLists(a,b) would return a list with the same length of the longest of the two from list a and list b. The function takes each corresponding element (the same index) from the list a and b, add them together and put the sum in the new list. If one of the list is shorter than the other, then the value/element from the longer list would be used. Below is the expected outcome:
a = [2,4,5,6]
b = [1,4,3 ]
c = addLists(a,b)
print(c) #would output [3,8,8,6]

Answers

Answered by Suhas107
0

Answer:

def addList(a,b):

i = 0

if len(a) > len(b):

c = a

else:

c = b

while(i < min(len(a),len(b))):

c[i] = a[i] + b[i]

i += 1

return c

Explanation:

The code is self explanatory

Similar questions