Quiz 07

flickr photo by Kaboedel https://flickr.com/photos/nerina/268955686 shared under a Creative Commons (BY-NC) license

Weekly Quiz

Write your code for the quiz, then:

  • email your answers (as file attachments) to Ken.
  • Most important: blog about your answers. You should explain the code, your process and link to code on GitHub.

The Quiz (same for both C++/Python)

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

What to Do

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’)
  • For C++, check here: http://www.cplusplus.com/reference/cmath/nan-function/

Example. If the input is [2,4,5,6] and [1,2,3,4] the result will be 49 since (2*1)+(4*2)+(5*3)+(6*4) = 49

Get Creative, put style in your Blog Posts

Make the posts your expression, be good internet citizens but also have fun!

flickr photo by Kaboedel https://flickr.com/photos/nerina/268955686 shared under a Creative Commons (BY-NC) license
flickr photo by Kaboedel https://flickr.com/photos/nerina/268955686 shared under a Creative Commons (BY-NC) license

CC BY-SA 4.0 Quiz 07 by Ken Bauer is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a Reply

Your email address will not be published. Required fields are marked *