This quiz in fact, it’s one of the things I do on physics class. Here are the instructions:
«Create a function called dot_product that receives two lists of numbers (say list1 and
list2). The function returns what is the dot product of the two lists.
For full marks, if the lists are not the same size, then the function should return the
special value of NaN (which represents not a number).»
I created two lists with arrays. And then the dot_product functions works with the formula s (for sum) –> s = s + (list1 [i] * list2 ); That inside of a for loop.
It was very easy, because of I know the formula from my physics class.
Here’s my GitHub if you want the code.
If you didn’t understand the dot product, for any reason, here’s a link that explains that topic.