You are on page 1of 1

Q1) 

Write a program in python that takes two lists of numbers of the same length, and  will print
the sum of the products of the corresponding elements of each (dot product).

Answer)Code

def dot(K,L):
if len(K)==len(L) and len(K)!=0:
return sum([K[n]*L[n] for n in range(len(K))])
else:
return 0

K = [4,2,6,7];
L = [3,9,10,17];

print(dot(K,L));

Output:

You might also like