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.
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.
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茅.
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.