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/


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!



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s