My Coding Quiz #35

Words
650
Reading
3 min
Listen
Play
3y

My Coding Quiz #35 馃懆鈥嶐煉火煕狅笍馃З

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: False. Line 1 creates a numeric variable num_block with the integer value one million (1,000,000).

The fact that it is written with underscores included in the numeric literal is irrelevant. The purpose of these underscores is to improve the readability of the number in the code for programmers. They are new in Python 3.6, which means that it has been around for a while and the feature exists in other languages as well. If you didn't know about it, it's been a waste, as it's quite useful.

Line 2 also creates a numeric variable tid and is worth 100,000. Note that the underscores here do not improve readability much, as we are not using them as expected, which is as thousand-unit separators. However, the point is that it does not create any syntax problems and its use is flexible.

I originally wanted the numeric literal for tid to have six zeros, so that it would be the same value as the num_block variable, but it looks like I accidentally "ate" a zero.

Anyway, line 3 compares both values, which are different, so _v is false and is what is printed at the end. We see that _v also has an underscore. In Python underscores have a few good uses. We'll see more of them later; maybe.


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 #35 馃懆鈥嶐煉火煕狅笍馃З

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: False. La l铆nea 1 crea una variable num茅rica num_block con el valor entero un mill贸n (1.000.000).

El hecho de que est茅 escrito con guiones bajos incluidos en el literal num茅rico es irrelevante. El prop贸sito de estos guiones bajos es mejorar la legibilidad del n煤mero en el c贸digo para los programadores. Son nuevas en Python 3.6, lo que significa que existe desde hace un tiempo y la caracter铆stica tambi茅n existe en otros lenguajes. Si no lo sab铆as, ha sido un desperdicio, ya que es bastante 煤til.

La l铆nea 2 tambi茅n crea una variable num茅rica tid y vale 100.000. Tenga en cuenta que los guiones bajos aqu铆 no mejoran mucho la legibilidad, ya que no los usamos como se esperaba, que es como separadores de mil unidades. Sin embargo, la cuesti贸n es que no crea ning煤n problema de sintaxis y su uso es flexible.

Originalmente quer铆a que el literal num茅rico de tid tuviera seis ceros, para que tuviera el mismo valor que la variable num_block, pero parece que accidentalmente "me com铆" un cero.

De todos modos, la l铆nea 3 compara ambos valores, que son diferentes, por lo que _v es falso y es lo que se imprime al final. Vemos que _v tambi茅n tiene un gui贸n bajo. En Python, los guiones bajos tienen algunos buenos usos. Veremos m谩s de ellos m谩s adelante; quiz谩s.


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.

My Coding Quiz #35 | Ecency