My Coding Quiz #10

Words
568
Reading
3 min
Listen
Play
3y

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

My Coding Quiz #10 | Ecency