[Type C]Q2. Write a program that takes any two lists L and M of the same size and adds their elements together to form 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] then N should equal[4,6,13].

Built-in functions with List

FUNCTIONDESCRIPTION
sum()Sums up the numbers in the list
cmp()This function returns 1, if first list is “greater” than second list
max()return maximum element of the given list
min()return minimum element of given list
len()Returns length of the list or size of the list
map()returns a list of the results after applying the given function to each item of a given iterable

Program code:

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

Output:

Enter list of integers : 3 1 4 
Enter list of integers : 1 5 9 
[4, 6, 13]

Two lists of integer are taken input from user.

Using the split() function, they are split into tokens, and elements of list belonging to the same index are added to form a third list.

This list is sum of the two lists taken as input and is printed on console.

Basic python functionality is demonstrated in above program.

To view all the lessons in chapter 1: http://computertutor.in/class-12-computer-science/chapter-2/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page