create account

My Coding Quiz #34 by eniolw

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

<center><h2>My Coding Quiz #34 👨‍💻🛠️🧩</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/DQmfUd4apTca5TSmZNBerwKYHvEQkRf2KG5QfXYNgnZK9R7/quiz_img_en.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-33">previous quiz</a>:</b> <b>SyntaxError</b>. Line 1 creates a list called <code>data</code> with numeric elements. The notation <code>.2</code> is perfectly valid, equivalent to <code>0.2</code> as is common in spoken English and in other contexts.</p>

<p>Line 2 creates a new list <code>nums</code> using list comprehension. Here a condition <code>.1 < d</code> is introduced which if you find slightly difficult to read, you can think of it as <code>d > .1</code> which is equivalent. The list <code>nums</code> will consist of <b>[0.2, 0.3]</b> which are the only values greater than <code>0.1</code> in <code>data</code>.</p>

<p>Line 3 creates a variable called <code>sum</code> and this is critical to understanding the quiz, as we will see. It then starts a for loop that iterates over <code>data</code> and accumulates its values in <code>sum</code>.</p>

<p>After that, line 6 tries to create a <code>total</code> variable from the sum of the elements of <code>nums</code> and here we have a problem. The name <code>sum</code> is partially reserved in Python for a built-in function that sums the elements of an iterable. However, that does not prevent it from being overwritten by the programmer and that is precisely what happened here in line 3 by saying <code>sum = 0</code>. The behavior of <code>sum</code> as a function has since been lost, which is why the code will generate a type error (<b>TypeError</b>), since the <code>sum</code> object is a float and is not callable as a function. Ĺa last line would not be executed.</p>

<p>As you can see, you must be careful when naming your variables. The name <code>sum</code> is very intuitive, but you should not use it in Python for such a thing.</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 #34 👨‍💻🛠️🧩</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/DQmerMF6deZYLJyoauSmvQZamYnZLNpmFrAt2HagtLEP8PQ/quiz_img_es.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-33">quiz anterior</a>:</b> <b>SyntaxError</b>. La línea 1 crea una lista llamada <code>data</code> con elementos numéricos. La notación <code>.2</code> es perfectamente válida, equivalente a <code>0.2</code> como es común en el inglés hablado y en otros contextos.</p>

<p>La línea 2 crea una nueva lista <code>nums</code> usando la comprensión de listas. Aquí se introduce una condición <code>.1 < d</code> que, si le resulta un poco difícil de leer, puede considerarla como <code>d > .1</code>, que es equivalente. La lista <code>nums</code> estará formada por <b>[0.2, 0.3]</b>, que son los únicos valores mayores que <code>0.1</code> en <code>data</code>.</p>

<p>La línea 3 crea una variable llamada <code>suma</code> y esto es fundamental para comprender el cuestionario, como veremos. Luego inicia un bucle for que itera sobre <code>data</code> y acumula sus valores en <code>sum</code>.</p>

<p>Después de eso, la línea 6 intenta crear una variable <code>total</code> a partir de la suma de los elementos de <code>nums</code> y aquí tenemos un problema. El nombre <code>sum</code> está parcialmente reservado en Python para una función incorporada que suma los elementos de un iterable. Sin embargo, eso no evita que el programador lo sobrescriba y eso es precisamente lo que sucedió aquí en la línea 3 al decir <code>sum = 0</code>. Desde entonces, el comportamiento de <code>sum</code> como función se ha perdido, por lo que el código generará un error de tipo (<b>TypeError</b>), ya que <code>sum</code> El objeto es un flotante y no se puede invocar como una función. Ĺuna última línea no se ejecutaría.</p>

<p>Como puedes ver, debes tener cuidado al nombrar tus variables. El nombre <code>sum</code> es muy intuitivo, pero no deberías usarlo en Python para tal cosa.</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 612 others
properties (23)
authoreniolw
permlinkmy-coding-quiz-34
categoryhive-196387
json_metadata"{"image":["https://images.ecency.com/DQmfUd4apTca5TSmZNBerwKYHvEQkRf2KG5QfXYNgnZK9R7/quiz_img_en.png","https://images.ecency.com/DQmerMF6deZYLJyoauSmvQZamYnZLNpmFrAt2HagtLEP8PQ/quiz_img_es.png"],"tags":["hive-196387","programming","coding","python","quiz","neoxian","proofofbrain","waivio","creativecoin","spanish"],"description":"My Coding Quiz #34 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.0.37-vision","format":"markdown+html","image_ratios":["0.9390","0.9390"]}"
created2023-11-19 00:59:18
last_update2023-11-19 00:59:18
depth0
children2
last_payout2023-11-26 00:59:18
cashout_time1969-12-31 23:59:59
total_payout_value5.750 HBD
curator_payout_value5.629 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,708
author_reputation255,322,644,496,399
root_title"My Coding Quiz #34"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id128,981,329
net_rshares24,942,047,333,347
author_curate_reward""
vote details (676)
@stemsocial ·
$0.08
re-eniolw-my-coding-quiz-34-20231119t155537225z
<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 (23)
authorstemsocial
permlinkre-eniolw-my-coding-quiz-34-20231119t155537225z
categoryhive-196387
json_metadata{"app":"STEMsocial"}
created2023-11-19 15:55:36
last_update2023-11-19 15:55:36
depth1
children0
last_payout2023-11-26 15:55:39
cashout_time1969-12-31 23:59:59
total_payout_value0.042 HBD
curator_payout_value0.042 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,918,491,691,707
root_title"My Coding Quiz #34"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id128,999,589
net_rshares182,458,116,839
author_curate_reward""
vote details (1)
@taradraz1 ·
I will say SyntaxError :D 🤠
properties (22)
authortaradraz1
permlinkre-eniolw-s4dlbz
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.10.1"}
created2023-11-19 14:52:48
last_update2023-11-19 14:52:48
depth1
children0
last_payout2023-11-26 14:52:48
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_length27
author_reputation14,630,618,255,247
root_title"My Coding Quiz #34"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id128,998,434
net_rshares0