create account

My Coding Quiz #50 by eniolw

View this thread on: hive.blogpeakd.comecency.com
· @eniolw ·
$13.20
My Coding Quiz #50
<div class="text-justify">

<center><h2>My Coding Quiz #50 👨‍💻🛠️🧩</h2></center>

<p>Welcome to the new installment of my series of <b>Coding Quizzes</b>, in which you will be able to test your knowledge and skills about programming and software development in a simple and fun way. If you want to learn more about it visit <a href="/@eniolw">my blog</a> here on Hive and the <a href="/@eniolw/my-coding-quiz-1">first post</a> where I introduced it.</p>

<h3>Without further ado, here's the riddle...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmVn5KJfaGwdhMbEaqSZJoCifJ2nQBkudb3VaTrcSpFLyA/imagen.png" alt="Quiz">
<h6>By @eniolw</h6>
</center>

<br><center><h3>What's your choice?</h3></center>

<p><b>Solution to the <a href="/@eniolw/my-coding-quiz-49">previous quiz</a>:</b> <b>None</b>. This quiz is a small nod to one of my favourite games after chess: The Legend of Zelda. First we define two sets: <code>player1</code> and <code>player2</code>, each containing titles from famous video games of this franchise.</p>

<p>However, it is in line 10 where we see the heart of the matter: <code>played = player1.intersection_update(player2)</code>. What the <code>intersection_update</code> method does is to select the common elements of both sets and overwrite the first one with those elements. So, if we print the content of <code>player1</code> we will see that it consists of <b>{"Majora's Mask"}</b>, as it is the only element that both sets have in common.</p>

<p>Now, don't be confused by the way the two common strings were hardcoded in the script: <code>"Majoras's Mask"</code> (line 3) is exactly the same as <code>'Majora\'s Mask'</code> (line 8), because in the second one, the backslash followed by <code>'</code> is one of the many Python escape sequences and serves to use that character inside a string delimited with that same character, making the notation legal.</p>

<p>But why <code>played</code> is <b>None</b> then? Because contrary to what you might think, the <code>intersection_update</code> method does not return a new set, but just updates one of the existing sets, so that method actually returns <b>None</b>. This is a misleading use, but not in vain, as it is a way to make a potential error explicit.</p>

<p>Majoras's Mask, by the way, is my favourite of all the Zelda games I've played. How about you?</p>

<hr>

<p>If you want to blog about computer science and programming content, I invite you to join <a href="/">Hive</a> and participate in its communities, such as <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> and others.</p>

<hr>

<center><h2>Mi Quiz de Programación #50 👨‍💻🛠️🧩</h2></center>

<p>Bienvenido a mi nueva serie de <b>Quizzes de Programación</b>, en la cual podrás poner a prueba tus conocimientos y habilidades sobre programación y desarrollo de software de una manera sencilla y divertida.  Si quieres aprender más sobre ella visita <a href="/@eniolw">mi blog</a> aquí en Hive y el <a href="/@eniolw/my-coding-quiz-1">primer post</a> donde la presenté.</p>

<h3>Sin más preámbulos, he aquí el acertijo...</h3>

<br>
<center>
<img src="https://images.ecency.com/DQmPF3Qs7s2X4sSLS5Rq3VHwFpiM1CKcRjJRqUhm72S2HV6/imagen.png" alt="Quiz">
<h6>Por @eniolw</h6>
</center>

<br><center><h3>¿Cuál es tu elección?</h3></center>

<p><b>Solución al <a href="/@eniolw/my-coding-quiz-49">quiz anterior</a>:</b> <b>None</b>. Este quiz es un pequeño guiño a uno de mis juegos favoritos después del ajedrez: The Legend of Zelda. Primero definimos dos conjuntos: <code>player1</code> y <code>player2</code>, cada uno de los cuales contiene títulos de videojuegos famosos de esta franquicia.</p>

<p>Sin embargo, es en la línea 10 donde vemos el meollo del asunto: <code>played = player1.intersection_update(player2)</code>. Lo que hace el método <code>intersection_update</code> es seleccionar los elementos comunes de ambos conjuntos y sobrescribir el primero con esos elementos. Entonces, si imprimimos el contenido de <code>player1</code> veremos que consta de <b>{"Majora's Mask"}</b>, ya que es el único elemento que ambos conjuntos tienen en común. </p>

<p>Ahora bien, no te dejes confundir por la forma en que las dos cadenas comunes estaban codificadas en el script: <code>"Majoras's Mask"</code> (línea 3) es exactamente igual que <code>'Majora\'s Mask'</code> (línea 8), porque en la segunda, la barra invertida seguida de <code>'</code> es una de las muchas secuencias de escape de Python y sirve para usar ese carácter dentro de una cadena delimitada con ese mismo carácter, lo que hace que la notación sea legal.</p>

<p>Pero ¿por qué entonces <code>played</code> es <b>None</b>? Porque, contrariamente a lo que podría pensar, el método <code>intersection_update</code> no devuelve un nuevo conjunto, sino que simplemente actualiza uno de los conjuntos existentes, por lo que ese método en realidad devuelve <b>None</b>. Este es un uso engañoso, pero no en vano, ya que es una forma de hacer explícito un posible error.</p>

<p>Majoras's Mask, por cierto, es mi favorito de todos los juegos de Zelda que he jugado. ¿Y tú?</p>

<hr>

<p>Si quieres bloguear sobre contenido informático y de programación, te invito a unirte a <a href="/">Hive</a> y participar en sus comunidades, tales como <a href="/created/hive-196387">STEM-social</a>, <a href="/created/hive-154226">Develop Spanish</a>, <a href="/created/hive-169321">Programming & Dev</a> y otras.</p>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 545 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-50
categoryhive-197685
json_metadata"{"image":["https://images.ecency.com/DQmVn5KJfaGwdhMbEaqSZJoCifJ2nQBkudb3VaTrcSpFLyA/imagen.png","https://images.ecency.com/DQmPF3Qs7s2X4sSLS5Rq3VHwFpiM1CKcRjJRqUhm72S2HV6/imagen.png"],"tags":["hive-197685","programming","coding","python","quiz","zelda","crypto","neoxian","proofofbrain","creativecoin","spanish"],"description":"My Coding Quiz #50 Welcome to the new installment of my series of Coding Quizzes, in which you will be able to test your knowledge and skills about programming and software development in a fun way.","app":"ecency/3.1.0-vision","format":"markdown+html","image_ratios":["1.0776","1.0776"]}"
created2024-03-06 18:17:36
last_update2024-03-06 18:17:36
depth0
children1
last_payout2024-03-13 18:17:36
cashout_time1969-12-31 23:59:59
total_payout_value6.670 HBD
curator_payout_value6.532 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,539
author_reputation255,504,196,782,418
root_title"My Coding Quiz #50"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id131,848,964
net_rshares22,724,884,058,493
author_curate_reward""
vote details (609)
@stemsocial ·
re-eniolw-my-coding-quiz-50-20240307t180510689z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-50-20240307t180510689z
categoryhive-197685
json_metadata{"app":"STEMsocial"}
created2024-03-07 18:05:09
last_update2024-03-07 18:05:09
depth1
children0
last_payout2024-03-14 18:05:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,919,140,450,815
root_title"My Coding Quiz #50"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id131,873,515
net_rshares0