My Coding Quiz #19 馃懆鈥嶐煉火煕狅笍馃З
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...
By
@eniolw
What's your choice?
Solution to the previous quiz: 4. Line 1 defines an list of characters a = ['0', '1', '2' '3']. Note that there is no comma between '2' and '3', so they are not separate elements. In fact, when Python sees contiguous literals like this, what it does is concatenate them into one. Thus, internally the list a consists of ['0', '1', '23']. This detail will be the essence of the exercise and the solution.
Line 2 makes a copy of a and calls it b. Line 3 adds a '5' element to b with the well-known append method, and line 4 removes the element located at the index 1 from to. Finally the length of b is printed.
Since b is a copy of a and it had a length of 3 when the copy was made, only the operation at line 3 affected the length of b, because a new element was added to it. Therefore, the value of b is ['0', '1', '23', '4'], which is an array of length 4 , the output obtained.
The quiz was successfully solved by @splash-of-angs63. Good job!
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 #19 馃懆鈥嶐煉火煕狅笍馃З
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...
Por
@eniolw
驴Cu谩l es tu elecci贸n?
Soluci贸n al quiz anterior: 4. La l铆nea 1 definie un arreglo de caracteres a = ['0', '1', '2' '3']. N贸tese que no hay coma entre '2' y '3', por lo que no son elementos separados. De hecho, cuando Python ve literales contiguos as铆, lo que hace es concatenarlos en uno solo. As铆, internamente el arreglo a consiste en ['0', '1', '23']. Este detalle ser谩 la esencia del ejercicio y la soluci贸n.
La l铆nea 2 hace una copia de a y la llama b. La l铆nea 3 a帽ade un elemento '5' a b con el bien conocido m茅todo append, y la l铆nea 4 retira el elemento ubicado en el 铆ndice 1 de a. Finalmente se imprime la longitud de b.
Como b es una copia de a y esta ten铆a una longitud de 3 cuando se hizo la copia, solo la operaci贸n de la l铆nea 3 afect贸 la longitud de b, pues se le a帽adi贸 un nuevo elemento. Por tanto, el valor de b es ['0', '1', '23', '4'], que es un arreglo de longitud 4, la salida obtenida.
El quiz fue resuelto satisfactoriamente por @splash-of-angs63. 隆Buen trabajo!
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.