Programming Examples

Python program that takes any two list L and M of the same size and adds their elements together in another third list


python program that takes any two list L and M of the same size and adds their elements together in another third list

Write a python program that takes any two list L and M of the same size and adds their elements together to from a new list N whose elements are sums of the corresponding elements in L and M.

For instance, if L=[3,1,4] and M= [1,5,9] the N should equal [4,6,13].

print("Enter Two list of same Size")
L=eval(input("Enter List 1 : "))
M=eval(input("Enter list 2 : "))
N=[]
if len(L)!=len(M):
    print("The size of both list are not same : ")
else:
    for a in range(0,len(M)):
        N.append(L[a]+M[a])
    print("Result List :",N)

Output

Enter Two list of same Size

Enter List 1 : [4,5,3,5,6]

Enter list 2 : [3,2,3,4,5]

Result List : [7, 7, 6, 9, 11]

>>> 

======================== 

Enter Two list of same Size

Enter List 1 : [1,2,3,4]

Enter list 2 : [1,2,4]

The size of both list are not same : 

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz