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: 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:
sum(a) is the sum of the elements of list a, which is 8.sum(b) is the sum of the elements of list b, which is 5.len(b) is the length of b, which is 4. Remember that one element was removed from it.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.
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: 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:
sum(a) es la suma de los elementos de la lista a, que es 8.sum(b) es la suma de los elementos de la lista b, que es 5.len(b) es la longitud de b, que es 4. Recuerda que se elimin贸 un elemento.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.