Quiz 7

Hey there! Let’s do the quiz #7.

Quiz 7 is about this:

“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). For Python, you can create this value with the expression: float(‘NaN’)”

Let me explain what is the dot product:

“In mathematics, the dot product, or scalar product (or sometimes inner product in the
context of Euclidean space), is an algebraic operation that takes two equal-length
sequences of numbers (usually coordinate vectors) and returns a single number.

Algebraically, it is the sum of the products of the corresponding entries of the two
sequences of numbers” Source: http://kenscourses.com/tc101winter2016/2016/04/quiz-07/

quiz7

Heeere’s my code. I’ll explain it step by step.

First of all we define our function “dot_product” that will determine if the lists that my user gave me are the same length or not.

If not, the program will return the NaN result. This will tell the user that he/she is doing something wrong.

Otherwise, the code will do the dot product.

Here’s the link to my code. Enjoy coding!!!! Byeeee!

CC BY-SA 4.0 Quiz 7 by paogarcia2401 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.