{"id":36912,"date":"2016-05-02T10:33:44","date_gmt":"2016-05-02T15:33:44","guid":{"rendered":"http:\/\/carlosdanielmartinezblog.wordpress.com\/?p=1135"},"modified":"2016-05-02T10:53:59","modified_gmt":"2016-05-02T15:53:59","slug":"quiz07-2","status":"publish","type":"post","link":"https:\/\/kenscourses.com\/tc101winter2016\/2016\/05\/quiz07-2\/","title":{"rendered":"#Quiz07"},"content":{"rendered":"<h1 style=\"text-align:center;\"><span style=\"color:#ff0000;\"><strong>Quiz 7<\/strong><\/span><\/h1>\n<p style=\"text-align:center;\">In mathematics, the dot product, or scalar product (or sometimes inner product in the<br \/>\ncontext of Euclidean space), is an algebraic operation that takes two equal-length<br \/>\nsequences 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<br \/>\nsequences of numbers<\/p>\n<p>Create a function called dot_product that receives two lists of numbers (say list1 and<br \/>\nlist2). The function returns what is the dot product of the two lists.<\/p>\n<p>For full marks, if the lists are not the same size, then the function should return the<br \/>\nspecial value of NaN (which represents not a number).<\/p>\n<ul>\n<li>For Python, you can create this value with the\u00a0expression: float(\u2018NaN\u2019)<\/li>\n<\/ul>\n<p>Example. If the input is [2,4,5,6] and [1,2,3,4] the result will be 49 since\u00a0(2*1)+(4*2)+(5*3)+(6*4) = 49<\/p>\n<p>&nbsp;<\/p>\n<p>Gracias a este programa podemos hacer el producto de dos listas, es muy simple ya que solamente multiplicamos cada numero de la lista uno por uno, pero exist\u00eda una excepci\u00f3n, que si el tama\u00f1o de las listas no eran iguales, entonces no se podr\u00eda realizar el producto de las listas, para lo que hice un condicional que se encarga de comparar el tama\u00f1o de las listas y te dice si son iguales o no, para saber el tama\u00f1o de la lista use la funci\u00f3n<span style=\"color:#000080;\"><em><strong> len<\/strong><\/em><\/span> de no serlo retorna<em><strong><span style=\"color:#000080;\"> NaN<\/span><\/strong><\/em>(Not a Number). En este programa utilice por primera vez un ciclo<span style=\"color:#000080;\"><em><strong> for<\/strong> <\/em><\/span>doble, para realizar la multiplicaci\u00f3n de las listas.<\/p>\n<p>Aqu\u00ed esta mi c\u00f3digo:<\/p>\n<p><span style=\"color:#0000ff;\">import<\/span> os<br \/>\nos.system(<span style=\"color:#ff9900;\">&#8220;clear&#8221;<\/span>)<br \/>\n<span style=\"color:#0000ff;\">print<\/span>(<span style=\"color:#ff9900;\">&#8220;scalar product&#8221;<\/span>)<br \/>\nlista1=[<span style=\"color:#99cc00;\">1<\/span>,<span style=\"color:#99cc00;\">2<\/span>,<span style=\"color:#99cc00;\">3<\/span>,<span style=\"color:#99cc00;\">4<\/span>]<br \/>\nlista2=[<span style=\"color:#99cc00;\">2<\/span>,<span style=\"color:#99cc00;\">4<\/span>,<span style=\"color:#99cc00;\">5<\/span>,<span style=\"color:#99cc00;\">6<\/span>]<\/p>\n<p><span style=\"color:#0000ff;\">def<\/span> <span style=\"color:#800080;\">dot_product<\/span>(var1,var2):<br \/>\nacum=<span style=\"color:#99cc00;\">0<\/span><br \/>\n<span style=\"color:#0000ff;\">if<\/span>(<span style=\"color:#0000ff;\">len<\/span>(var1)==<span style=\"color:#0000ff;\">len<\/span>(var2)):<br \/>\n<span style=\"color:#0000ff;\">for<\/span> l1,l2 <span style=\"color:#0000ff;\">in zip<\/span>(var1,var2):<br \/>\nsuma=l1*l2<br \/>\nacum=acum+suma<br \/>\n<span style=\"color:#0000ff;\">print<\/span>(acum)<br \/>\n<span style=\"color:#0000ff;\">else<\/span>:<br \/>\n<span style=\"color:#0000ff;\">print<\/span>(<span style=\"color:#ff9900;\">&#8220;NaN&#8221;<\/span>)<\/p>\n<p>dot_product(lista1,lista2)<\/p>\n<p>Por aqu\u00ed el enlace a <a href=\"https:\/\/github.com\/iDannymt\/Fundamentos-De-Programaci-n\/commit\/af921f3d025cf1a5f08508cadcee20a9d0a0feb7\">GitHub<\/a><\/p>\n<p>Por ac\u00e1 el programa funcionando:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1171\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/6d3790a6d4826b34b16020063c71c207.jpg\" alt=\"ESTEYA\"   \/><img decoding=\"async\" class=\"alignnone size-full wp-image-1170\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/37918d61ce6bcf79ad15d47a217cc6c1.jpg\" alt=\"ESTETAMBIEN\"   \/><\/p>\n<p>&nbsp;<\/p>\n<p>  <a rel=\"nofollow\" href=\"http:\/\/feeds.wordpress.com\/1.0\/gocomments\/carlosdanielmartinezblog.wordpress.com\/1135\/\"><img decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/9671b7caabe2cacadc49a153d06fedfc.jpg\" \/><\/a> <img loading=\"lazy\" decoding=\"async\" alt=\"\" border=\"0\" src=\"http:\/\/kenscourses.com\/tc101winter2016\/wp-content\/uploads\/2016\/05\/5a7b24919f2aab009b0734c60ca5ed47.jpg#038;blog=105448664&#038;%23038;post=1135&#038;%23038;subd=carlosdanielmartinezblog&#038;%23038;ref=&#038;%23038;feed=1\" width=\"1\" height=\"1\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quiz 7 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 &hellip; <a href=\"https:\/\/kenscourses.com\/tc101winter2016\/2016\/05\/quiz07-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">#Quiz07<\/span><\/a><\/p>\n","protected":false},"author":48,"featured_media":36925,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[133],"class_list":["post-36912","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","category-syndicated","tag-quizzes"],"_links":{"self":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/comments?post=36912"}],"version-history":[{"count":2,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36912\/revisions"}],"predecessor-version":[{"id":36932,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/posts\/36912\/revisions\/36932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media\/36925"}],"wp:attachment":[{"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/media?parent=36912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/categories?post=36912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenscourses.com\/tc101winter2016\/wp-json\/wp\/v2\/tags?post=36912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}