My Coding Quiz #8

avatar

My Coding Quiz #8 👨‍💻🛠️🧩

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: [3, 1]. Line 1 specifies a list containing numeric elements and is called x. The same thing happens on the next line, except that the list is empty and is identified as y.

The heart of the matter is given in lines 3 and 4, where these two lists are iterated over and expanded with new elements. Specifically, the numeric sequence given to the for loop is defined as range(1, 5, 2). This means that it will consist of numbers between 1 and 5, but incrementing at the rate of 2, which is the third argument of the range.

In this way, the sequence starts at 1, increments to 3 and then stops, since it cannot increment to 5 because 5 is the specified stop and we know that this stop value is non-inclusive. The numbers returned by this range, therefore, will be 1 and 3, which are the values that the i variable of the for loop will take.

So, it's not hard to see that the y list will be expanded with the values of the x list at indices 1 and 3, and these values are 3 and 1 respectively. Hence [3, 1] is the output produced on the final line.

I'd say the gist of the puzzle is knowing the role of incrementing the range by 2, which is not difficult if you're familiar with Python. Once again, @rafaelaquino has solved this exercise. What a great ability to read and execute code in your head!


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 #8 👨‍💻🛠️🧩

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: [3, 1]. La línea 1 especifica una lista que contiene elementos numéricos y se llama x. Lo mismo pasa en la línea siguiente, excepto que la lista está vacía y se indentifica como y.

El meollo del asunto se da en las líneas 3 y 4, donde estas dos listas son iteradas y expandidas con nuevos elementos. Específicamente, la secuencia numérica dada al for está definida como range(1, 5, 2). Esto significa que comprenderá los números entre 1 y 5, pero incrementando a ritmo de 2, que es el tercer argumento del range.

De esta manera, la secuencia comienza en 1, incrementa a 3 y luego se detiene, pues no puede incrementar a 5 por cuanto 5 es el tope especificado y sabemos que este tope es no inclusivo. Los números retornados por este range, por tanto, serán 1 y 3, que son los valores que tomará la variable i del for.

Así, no es difícil ver que la lista y será expandida con los valores de la lista x en los índices 1 y 3, y estos valores son 3 y 1 respectivamente. De allí que [3, 1] sea la salida producida en la línea final.

Diría que la esencia del acertijo está en conocer el papel de incremento en 2 del range, algo nada difícil si estás familiarizado con Python. Una vez más, @rafaelaquino ha resuelto este ejercicio. ¡Qué buena habilidad para leer y ejecutar código mentalmente!


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
7 comments
avatar

Contento y muy emocionado por mi participación en el reto anterior. Le felicito porque ésta es una manera muy efectiva para promocionar uno de los lenguajes de programación más populares y de mayor demanda en la actualidad. Seguiré pendiente de tus retos!

0
0
0.000
avatar

Seguro. Gracias por participar!

0
0
0.000
avatar

This is quite interesting,I love python for it's cast application, you just reminded me of a friend who is into data analysis, he does more of this each time I visit him. Thanks for sharing

0
0
0.000
avatar

Yeah, Python is quite popular for that. Thanks for stopping by.

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