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: SS. Line 1 defines a string a with the content " Science ". Note the deliberate presence of whitespace at the beginning and end of the string.
Line 2 creates a b variable. To do this, first whitespace at the beginning and end of a is removed using the built-in strip method. A special slice is then applied using the [::-1] notation. This is another of many ways to create a reversed list in Python. The -1 at the end indicates that the step should be done one at a time, but in reverse. In the end, the value of b will be 'ecneicS'.
Line 3 creates a variable c with a and b elements accessed by indexes. We know that the element at index 1 of a has the value 'S', and it is not surprising that the element at index -1 of b corresponds to the last one, whose value is also 'S'. The value of c, therefore, will be 'SS', which is printed at line 4.
Both @rafaelaquino and
@jesalmofficial solved this quiz and
@jesalmofficial even provided an explanation. Very good!
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: SS. La l铆nea 1 define una cadena de caracteres a con el contenido " Science ". N贸tese la presencia deliberada de espacios en blanco al principio y final de la cadena.
La l铆nea 2 crea una variable b. Para ello, primero se remueven los espacios en blanco al principio y al final de a usando el m茅todo incorporado strip. Luego se aplica un rebanado especial usando la notaci贸n [::-1]. Esta es otra de muchas maneras de crear una lista invertida en Python. El -1 al final indica que el paso debe hacerse de uno en uno, pero en sentido contrario. Al final, el valor de b ser谩 'ecneicS'.
La l铆nea 3 crea una variable c con elementos de a y b accedidos mediante 铆ndices. Sabemos que el elemento en el 铆ndice 1 de a posee el valor 'S', y no es una sorpresa que el elemento en el 铆ndice -1 de b corresponda al 煤ltimo, cuyo valor tambi茅n es 'S'. El valor de c, por tanto, ser谩 'SS', lo impreso en la l铆nea 4.
Tanto @rafaelaquino como
@jesalmofficial resolvieron este quiz y
@jesalmofficial incluso provey贸 una explicaci贸n. 隆Muy bien!
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.