My Coding Quiz #29

in #hive-19638711 months ago

My Coding Quiz #29 👨‍💻🛠️🧩

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 simple and fun way. If you want to learn more about it visit my blog here on Hive and the first post where I introduced it.

Without further ado, here's the riddle...




Quiz
By @eniolw


What's your choice?

Solution to the previous quiz: Line 1 simply creates a d list of two numeric elements, while line 2 creates an inline func function that takes a parameter and applies the pop method to it., returning the removed value.

Line 3 introduces the function all, which evaluates a list that, as we will see, is modified at run time. We see that func is called a couple of times, providing the list d as an argument and this is modified, since it is a pass by reference. By the time the value of the third list element on line 3 is evaluated, d will be empty, so it will be considered Falsy. The results that all will evaluate will then be -1, 2 and [].

The all function returns True if and only if all the elements in the given list are Truthy, but in our case that is impossible. Hence the value of r is False and is what is printed on the screen at the end.


If you want to blog about computer science and programming content, I invite you to join Hive and participate in its communities, such as STEM-social, Develop Spanish, Programming & Dev and others.


Mi Quiz de Programación #29 👨‍💻🛠️🧩

Bienvenido a mi nueva serie de Quizzes de Programación, 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 mi blog aquí en Hive y el primer post donde la presenté.

Sin más preámbulos, he aquí el acertijo...




Quiz
Por @eniolw


¿Cuál es tu elección?

Solución al quiz anterior: False. La línea 1 simplemente crea una lista d de dos elementos numéricos, mientras que la línea 2 crea una función inline func que toma un parámetro y le aplica el método pop, devolviendo el valor retirado.

La línea 3 introduce la función all, la cual evalúa una lista que, como veremos, es modificada en tiempo de ejecución. Vemos que se llama a func un par de veces, proveyendo la lista d como argumento y esta es modificada, pues es un paso por referencia. Para cuando se evalúe el valor del tercer elemento de la lista de la linea 3, d estará vacía, por lo que se considerará como Falsy (falso). Los resultados que evaluará all serán entonces -1, 2 y [].

La función all retorna True si y solo si todos los elementos de la lista dada son Truthy (verdaderos), pero en nuestro caso eso es imposible. De allí que el valor de r es False y es lo impreso en pantalla al final.


Si quieres bloguear sobre contenido informático y de programación, te invito a unirte a Hive y participar en sus comunidades, tales como STEM-social, Develop Spanish, Programming & Dev y otras.

Sort:  

@tipu curate 8

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord 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. 
 

Opción C (True)