Q. Write a program that takes any two list l and m of the same size and adds their elements together to form a new list n whose element are sum of the corresponding elements in l and m.


You can understand by Watching video :-



Answer :-

l = eval(input("Enter first  list = "))
m = eval(input("Enter second list = "))
n = [ ]

for i in range(len(l)):
    n = n + [ l [ i ] + m [ i ] ]

print("New list = ",n)

Output :-

Enter first  list = [1,2,3,4,5,6,7,8,9]
Enter second list = [1,2,3,4,5,6,7,8,9]
New list =  [2, 4, 6, 8, 10, 12, 14, 16, 18]

>>> 

Enter first  list = [9,8,7,6,5,4,3,2,1]
Enter second list = [1,2,3,4,5,6,7,8,9]
New list =  [10, 10, 10, 10, 10, 10, 10, 10, 10]

>>> 

Enter first  list = [89,64,37,58,41,39]
Enter second list = [58,96,74,38,21,98]
New list =  [147, 160, 111, 96, 62, 137]

>>>


2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Third line error pls check

    ReplyDelete
    Replies
    1. Program is correct with no error. I think you have not enter list of same length.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post