I have this task to do the dot product of two vectors in the form of lists. I tried this method but it gives me the wrong answer, not quite sure what the issue is.
def scalar_product(vec1,vec2):
new_list = []
a_zip = zip(vec1, vec2)
result = 1
zipped_list = list(a_zip)
for lists in zipped_list:
for integer in lists:
result = result * integer
new_list.append(result)
return sum(new_list)
print(scalar_product([1,1,1],[2,2,2]))
So my thought process here was to first zip the lists together so I get one big list containing sublists. Then I looped through the lists and the sublist to multiply the values in the sub-lists and append that to a new_list. And then to sum up the new_list. But the output here is 21 when it actually should be 6.
I don't want to import any modules or such for this.