My Coding Quiz #9

in #hive-196387last year

My Coding Quiz #9 👨‍💻🛠️🧩

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: 25. Line 1 defines a list, which is entirely made up of numeric elements. This is good because they can be sorted. The sorting is carried out in the next line using the already known sort function, with the particularity that we specify that it sorts in the opposite direction by means of the argument reverse=True. Therefore, the list b is equal to [5, 3, 1, 0, -1].

We then apply the pop method to list b, which allows us to remove the element of the list whose index we specify, modifying the list. As we specified pop(1), the element at index 1, whose value is 3, will be removed. That value is returned by pop and assigned to the variable c.

Finally, we get the values and solve the arithmetic of line 4:

  1. sum(a) is the sum of the elements of list a, which is 8.
  2. sum(b) is the sum of the elements of list b, which is 5.
  3. len(b) is the length of b, which is 4. Remember that one element was removed from it.
  4. c is 3.

Therefore, we have that 8 + 5 + 4 * 3 equals 25, which is the snippet output.

Did you know about the reverse parameter and the pop method? It seems that @splash-of-angs63 did, since he managed to solve this puzzle!


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

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: 25. La línea 1 define una lista, que se compone enteramente de elementos numéricos. Esto es bueno porque se pueden ordenar. La ordenación se realiza en la siguiente línea utilizando la ya conocida función sort, con la particularidad de que especificamos que ordene en sentido contrario mediante el argumento reverse=True. Por tanto, la lista b es igual a [5, 3, 1, 0, -1].

A continuación, aplicamos el método pop a la lista b, que nos permite eliminar el elemento de la lista cuyo índice especifiquemos, modificando la lista. Como especificamos pop(1), se eliminará el elemento en el índice 1, cuyo valor es 3. Ese valor es devuelto por pop y asignado a la variable c.

Finalmente, obtenemos los valores y resolvemos la aritmética de la línea 4:

  1. sum(a) es la suma de los elementos de la lista a, que es 8.
  2. sum(b) es la suma de los elementos de la lista b, que es 5.
  3. len(b) es la longitud de b, que es 4. Recuerda que se eliminó un elemento.
  4. c es 3.

Por lo tanto, tenemos que 8 + 5 + 4 * 3 es igual a 25, que es el resultado del snippet.

¿Sabías sobre el parámetro reverse y el método pop? ¡Parece que @splash-of-angs63 lo hizo, ya que logró resolver este rompecabezas!


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.

Sort:  

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. 
 

Since w=4, x is basically the string '8' obtained from multiplying w by 2. Multiplying the string by 3 gives us y which comes out to be '888'. z creates another list by repeating y twice. Thus Z = ['888','888']

Thanks for participating. We'll see about your answer in the next installment :)