My Coding Quiz #7

avatar
(Edited)

My Coding Quiz #7 👨‍💻🛠️🧩

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: 4 []. Line 1 defines a variable p containing a range object, which is an immutable sequence of integers. It is specified to start at 0 (inclusive) and end at 5 (exclusive), i.e., it spans 0, 1, 2, 3 and 4.

This range object is iterated through a for in line 4, which could have been reduced to a single line as for i in range(0, 5). The for loop iterates through the sequence without doing anything else and the last value of i will be 4. It cannot be 5 because the for loop derives its indices from the already pre-established p sequence.

Line 2 defines a range object from 0 to -3, different from the previous one. By default, the range object iterates at a step of positive 1 and is made in such a way that it could not create an infinite loop. When this sequence is converted to a list at line 3, the list will be empty.

Hence the output instructed in line 6 is 4 []. That wasn't so hard, was it? @rafaelaquino managed to solve this riddle. Nice!


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, Hive Learners and others.


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

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: 4 []. La línea 1 define una variable p que contiene un objeto de rango, que es una secuencia inmutable de enteros. Se especifica que comienza en 0 (inclusivo) y termina en 5 (exclusivo), es decir, abarca 0, 1, 2, 3 y 4.

Este objeto de rango se itera a través de un for en la línea 4, que podría haberse reducido a una sola línea como for i in range(0, 5). El for itera a través de la secuencia sin hacer nada más y el último valor de i será 4. No puede ser 5 porque el bucle for deriva sus índices de la secuencia p ya preestablecida.

La línea 2 define un objeto de rango de 0 a -3, diferente al anterior. Por defecto, el objeto de rango itera en un paso de 1 positivo y está hecho de tal manera que no puede crear un bucle infinito. Cuando esta secuencia se convierta en una lista en la línea 3, la lista estará vacía.

Por lo tanto, la salida indicada en la línea 6 es 4 []. No fue tan difícil, ¿verdad? @rafaelaquino logró resolver este acertijo. ¡Genial!


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, Hive Learners y otras.



0
0
0.000
5 comments
avatar

La respuesta correcta del acertijo anterior me saltó a la vista! Ahora Corresponde resolver este nuevo reto.

0
0
0.000
avatar

Es esta oportunidad mi respuesta no está en la lista de posibles soluciones.
Mi solución es:
[1,3]

0
0
0.000
avatar

Revisa de nuevo :)
Check again :)

0
0
0.000
avatar

Saludos.
Cuando era: x = [0,1,2,3,4], mi respuesta era [1,3]. Es probable que mi vista falló. :)

Ahora x = [4,3,2,1,0,-1]
mi respuesta es:
[3, 1]

0
0
0.000
avatar

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. 
 

0
0
0.000