My Coding Quiz #28

in #hive-19638711 months ago

My Coding Quiz #28 👨‍💻🛠️🧩

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: AttributeError. Line 1 creates a tuple with 3 elements and names it z.

Line 2 applies the pop method to the tuple and this generates the exception AttributeError: 'tuple' object has no attribute 'pop', which is enough self-explanatory.

Let's remember that tuples are not lists and when encoding we must keep their differences in mind. Since tuples are immutable, there is no point in trying to modify them with the pop method.

As for line 3, it is not executed within the framework of the complete program due to the previous exception.

Now, if z were not a tuple but a list, the program would have been valid and we would have obtained 0b01 as output. I'll leave it to you to figure out why that's the case.


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

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: AttributeError. La línea 1 crea una tupla con 3 elementos y la llama z.

La línea 2 le aplica el método pop a la tupla y esto genera la excepción AttributeError: 'tuple' object has no attribute 'pop' (AttributeError: el objeto tupla no tiene el atributo pop), que ya es suficientemente autoexplicativa.

Recordemos que las tuplas no son listas y a la hora de codificar debemos tener presente sus diferencias. Puesto que las tuplas son inmutables, no tiene sentido tratar de modificarlas con el método pop.

En cuanto a línea 3, no llega a ejecutarse en el marco del programa completo por la excepción previa.

Ahora bien, si z no fuese una tupla sino una lista, el programa habría sido válido y habríamos obtenido una como salida 0b01. Te dejo a ti averiguar porqué ese es el caso.


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.

Sort:  

@tipu curate 4

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.