My Coding Quiz #10

avatar

My Coding Quiz #10 👨‍💻🛠️🧩

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: ['888', '888']. First a variable w of numeric value 4 is created. This value is then doubled and converted to a character, resulting in the value '8' being assigned to the variable x.

Next, on line 3 we get a string by tripling the contents of x, resulting in the immutable value '888'. This is a Python feature that applies arithmetic operators to strings, so this is not a bug. Along the same line, a y list is created with the newly obtained value.

On line 4 we see another Pythonic trick that applies the * operator to lists. What it does is create a new list with as many copies of y as specified. In this case it's two copies of y (z = y * 2), which translates to ['888', '888'] which is the value printed on the final line.

Did you know these other uses of the * operator in Python? Believe me, they are not all there is! Congratulations to @splash-of-angs63 for solving this quiz.


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

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: ['888', '888']. Primero se crea una variable w de valor numérico 4. Seguidamente, este valor se duplica y se convierte a un caracter, lo que resulta en el valor '8' que se asigna a la variable x.

Acto seguido, en la línea 3 obtenemos una cadena de caracteres triplicando el contenido de x, dando como resultado el valor inmutable '888'. Se trata de un artificio de Python que aplica operadores aritméticos a las cadenas de caracteres, por lo que no se trata de un error. En esa misma línea, se crea una lista y con el valor recien obtenido.

En la línea 4 volvemos a ver otro artificio Pythónico que aplica el operador * a las listas. Lo que hace es crear una nueva lista con tantas copias de y como se haya especificado. En este caso son dos copias de y (z = y * 2), lo que se traduce en ['888', '888'] que es el valor impreso en la línea final.

¿Conocías estos otros usos del operador * en Python? ¡Créeme, no son todos los que hay! Felicitaciones a @splash-of-angs63 por resolver este quiz.


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

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
avatar

The second code here converts m to uppercase and creates a list having each of the three characters, i.e., [‘A’, ‘B’, ‘C’]. Now, the print code will code for the first 2 characters of m (ab) and first 4 characters of n. Since in n only three characters are there. So this will deduce to [‘A’, ‘B’, ‘C’]. So, the answer should be ab [‘A’, ‘B’, ‘C’].

0
0
0.000
avatar

Thanks for your input! We'll see about that next time.

0
0
0.000
avatar

The answer for me its abc['A' ,'B','C',None], arrays start from 0 not 1 so, saying m[:2] means first 3 letters in lowercase abc and then n[:4] means 4 spaces in array, first 3 are A, B and C and theres no more so None at the end, i guess, im kind of confused now but i will go with that answer.

0
0
0.000
avatar

Noted! I will reveal the solution in the next installment. Keep and eye on it if you want.

0
0
0.000