Quiz10

The Question 1 of the quizz was just to create a function that received a list and returned the sum of the elements of the list that were evenly divisible by 3. To accomplish the objective, it was just matter of creating a ”for” loop that goes over each element of the list checking the condition, If the condition was true, then, that element was added to a variable containing the sum.

For the question 2, we had to create a function that received to vectors (lists) and returned the dot product. For that, we have to check first if the vectors have the same lenght (using ‘len’), if the lenght of the two vectors is different, the function has to return an error, but if it is the same returns the dot product. To get the dot product of the two vectors I created a ‘for’loop with a range of the lengh of the vectors. the variable changing of the loop was the index of both lists. So I created another variable containing the sum, which for every cycles gets added the product of the corresponding index element of the list.

Here are my solutions for the quizz:

Question 1: https://github.com/Manuelmv94/Quizz10/blob/master/q1.py

Question 2: https://github.com/Manuelmv94/Quizz10/blob/master/q2.py

 

CC BY 4.0 Quiz10 by Manuel Madrigal is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.