Professional Documents
Culture Documents
The Sum of The Products of The Corresponding Elements of Each (Dot Product) - Answer) Code
The Sum of The Products of The Corresponding Elements of Each (Dot Product) - Answer) Code
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: