diff --git a/_sources/quiz/Quiz10_en.rst b/_sources/quiz/Quiz10_en.rst index da72374b97..b7393b7197 100644 --- a/_sources/quiz/Quiz10_en.rst +++ b/_sources/quiz/Quiz10_en.rst @@ -14,16 +14,16 @@ Quiz - 10 .. activecode:: q10_1_en :nocodelens: - Develop the function ``cuantas_donas`` that takes ``n``, a positive integer, as a parameter, + Develop the function ``how_many_donuts`` that takes ``n``, a positive integer, as a parameter, and returns a string in the form of ``"Number of donuts: n"``, where ``n`` is the value - passed to the function as an argument. However, if ``n`` >= 10, ``cuantas_donas`` will + passed to the function as an argument. However, if ``n`` >= 10, ``how_many_donuts`` will return ``"many"`` instead of ``n``. |br| |br| Examples: |br| - ``cuantas_donas(5)`` -> ``"Number of donuts: 5"`` |br| - ``cuantas_donas(23)`` -> ``"Number of donuts: many"`` |br| + ``how_many_donuts(5)`` -> ``"Number of donuts: 5"`` |br| + ``how_many_donuts(23)`` -> ``"Number of donuts: many"`` |br| ~~~~ - def cuantas_donas(n): + def how_many_donuts(n): ==== @@ -33,15 +33,15 @@ Quiz - 10 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(cuantas_donas(4), "Number of donuts: 4", "Expected output: Number of donuts: 4") - self.assertEqual(cuantas_donas(9), "Number of donuts: 9", "Expected output: Number of donuts: 9") + self.assertEqual(how_many_donuts(4), "Number of donuts: 4", "Expected output: Number of donuts: 4") + self.assertEqual(how_many_donuts(9), "Number of donuts: 9", "Expected output: Number of donuts: 9") self.assertEqual( - cuantas_donas(10), + how_many_donuts(10), "Number of donuts: many", "Expected output: Number of donuts: many", ) self.assertEqual( - cuantas_donas(99), + how_many_donuts(99), "Number of donuts: many", "Expected output: Number of donuts: many", ) @@ -55,15 +55,15 @@ Quiz - 10 .. activecode:: q10_2_en :nocodelens: - Develop the function ``cadena_de_extremos`` that, given a string ``s``, + Develop the function ``chain_of_extremes`` that, given a string ``s``, returns a string with the first two and last two letters of ``s``. However, if the string has less than 2 letters, it returns an empty string. |br| |br| Examples: |br| - ``cadena_de_extremos("palmeras")`` -> ``"paas"`` |br| - ``cadena_de_extremos("a")`` -> ``""`` |br| + ``chain_of_extremes("palms")`` -> ``"pams"`` |br| + ``chain_of_extremes("a")`` -> ``""`` |br| ~~~~ - def cadena_de_extremos(s): + def chain_of_extremes(s): ==== @@ -73,12 +73,12 @@ Quiz - 10 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(cadena_de_extremos("palmeras"), "paas", "Expected output: paas") - self.assertEqual(cadena_de_extremos("algoritmos"), "alos", "Expected output: alos") - self.assertEqual(cadena_de_extremos("co"), "coco", "Expected output: coco") - self.assertEqual(cadena_de_extremos("a"), "", "Expected output: ''") - self.assertEqual(cadena_de_extremos("xyz"), "xyyz", "Expected output: xyyz") - self.assertEqual(cadena_de_extremos(""), "", "Expected output: ''") + self.assertEqual(chain_of_extremes("palms"), "pams", "Expected output: pams") + self.assertEqual(chain_of_extremes("algorithms"), "alms", "Expected output: alms") + self.assertEqual(chain_of_extremes("co"), "coco", "Expected output: coco") + self.assertEqual(chain_of_extremes("a"), "", "Expected output: ''") + self.assertEqual(chain_of_extremes("xyz"), "xyyz", "Expected output: xyyz") + self.assertEqual(chain_of_extremes(""), "", "Expected output: ''") myTests().main() @@ -89,17 +89,17 @@ Quiz - 10 .. activecode:: q10_3_en :nocodelens: - Develop the function ``remplazar_primer_caracter`` that, given a string ``s``, + Develop the function ``replace_first_character`` that, given a string ``s``, returns a string in which all occurrences of the first character in ``s`` are replaced by "*", except for the first one. **Note:** use the method ``.replace(value_to_replace, new_value)`` to solve the exercise. |br| |br| Examples: |br| - ``remplazar_primer_caracter("google")`` -> ``"goo*le"`` |br| - ``remplazar_primer_caracter("dona")`` -> ``"dona"`` |br| + ``replace_first_character("google")`` -> ``"goo*le"`` |br| + ``replace_first_character("donut")`` -> ``"donut"`` |br| ~~~~ - def remplazar_primer_caracter(s): + def replace_first_character(s): ==== @@ -109,10 +109,10 @@ Quiz - 10 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(remplazar_primer_caracter("babble"), "ba**le", "Expected output: ba**le") - self.assertEqual(remplazar_primer_caracter("aardvark"), "a*rdv*rk", "Expected output: a*rdv*rk") - self.assertEqual(remplazar_primer_caracter("google"), "goo*le", "Expected output: goo*le") - self.assertEqual(remplazar_primer_caracter("dona"), "dona", "Expected output: dona") + self.assertEqual(replace_first_character("babble"), "ba**le", "Expected output: ba**le") + self.assertEqual(replace_first_character("aardvark"), "a*rdv*rk", "Expected output: a*rdv*rk") + self.assertEqual(replace_first_character("google"), "goo*le", "Expected output: goo*le") + self.assertEqual(replace_first_character("donut"), "donut", "Expected output: donut") myTests().main() @@ -123,7 +123,7 @@ Quiz - 10 .. activecode:: q10_4_en :nocodelens: - Develop the function ``combinar_dos_cadenas`` that takes two strings as + Develop the function ``combine_two_chains`` that takes two strings as arguments, ``a`` and ``b``, and returns a new string in the following way: - The new string has to be a combination of ``a`` and ``b``. @@ -133,11 +133,11 @@ Quiz - 10 Suppose that ``a`` and ``b`` have more than 2 characters. For better clarification, see the following examples. |br| |br| Examples: |br| - ``combinar_dos_cadenas("mix", "pod")`` -> ``"pox mid"`` |br| - ``combinar_dos_cadenas("pezzy", "firm")`` -> ``"fizzy perm"`` |br| + ``combine_two_chains("mix", "pod")`` -> ``"pox mid"`` |br| + ``combine_two_chains("pezzy", "firm")`` -> ``"fizzy perm"`` |br| ~~~~ - def combinar_dos_cadenas(a, b): + def combine_two_chains(a, b): ==== @@ -147,14 +147,14 @@ Quiz - 10 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(combinar_dos_cadenas("mix", "pod"), "pox mid", "Expected output: pox mid") - self.assertEqual(combinar_dos_cadenas("dog", "dinner"), "dig donner", "Expected output: dig donner") + self.assertEqual(combine_two_chains("mix", "pod"), "pox mid", "Expected output: pox mid") + self.assertEqual(combine_two_chains("dog", "dinner"), "dig donner", "Expected output: dig donner") self.assertEqual( - combinar_dos_cadenas("gnash", "sport"), + combine_two_chains("gnash", "sport"), "spash gnort", "Expected output: spash gnort", ) - self.assertEqual(combinar_dos_cadenas("pezzy", "firm"), "fizzy perm", "Expected output: fizzy perm") + self.assertEqual(combine_two_chains("pezzy", "firm"), "fizzy perm", "Expected output: fizzy perm") myTests().main() @@ -166,15 +166,15 @@ Quiz - 10 .. activecode:: q10_5_en :nocodelens: - Develop the function ``es_palindromo`` that takes a string ``s`` as + Develop the function ``is_palindrome`` that takes a string ``s`` as parameter and checks if ``s`` is a palindrome or not, returning ``True`` or ``False`` accordingly. |br| |br| Examples: |br| - ``es_palindromo("asa")`` -> ``True`` |br| - ``es_palindromo("casa")`` -> ``False`` |br| + ``is_palindrome("ivi")`` -> ``True`` |br| + ``is_palindrome("civil")`` -> ``False`` |br| ~~~~ - def es_palindromo(s): + def is_palindrome(s): ==== @@ -184,12 +184,12 @@ Quiz - 10 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(es_palindromo("asa"), True, "Expected output: True") - self.assertEqual(es_palindromo("casa"), False, "Expected output: False") - self.assertEqual(es_palindromo("reconocer"), True, "Expected output: True") - self.assertEqual(es_palindromo("palabra"), False, "Expected output: False") - self.assertEqual(es_palindromo("radar"), True, "Expected output: True") - self.assertEqual(es_palindromo("seres"), True, "Expected output: True") + self.assertEqual(is_palindrome("ivi"), True, "Expected output: True") + self.assertEqual(is_palindrome("civil"), False, "Expected output: False") + self.assertEqual(is_palindrome("level"), True, "Expected output: True") + self.assertEqual(is_palindrome("word"), False, "Expected output: False") + self.assertEqual(is_palindrome("radar"), True, "Expected output: True") + self.assertEqual(is_palindrome("kayak"), True, "Expected output: True") myTests().main() @@ -200,14 +200,14 @@ Quiz - 10 .. activecode:: q10_6_en :nocodelens: - Develop the function ``contar_ocurrencias`` that takes two parameters: - ``frase`` and ``palabra``, both of type string. The function should return - the number of times that ``palabra`` occurs in ``frase``. |br| |br| + Develop the function ``count_occurrences`` that takes two parameters: + ``phrase`` and ``word``, both of type string. The function should return + the number of times that ``word`` occurs in ``phrase``. |br| |br| Examples: |br| - ``contar_ocurrencias("a ana y a mariana les gustan las manzanas", "ana")`` -> ``3`` |br| + ``count_occurrences("ana and mariana like amanatsu", "ana")`` -> ``3`` |br| ~~~~ - def contar_ocurrencias(frase, palabra): + def count_occurrences(frase, palabra): ==== @@ -218,11 +218,11 @@ Quiz - 10 def testOne(self): self.assertEqual( - contar_ocurrencias("a ana y a mariana les gustan las manzanas", "ana"), + count_occurrences("ana and Mariana like amanatsu", "ana"), 3, "Expected output: 3", ) - self.assertEqual(contar_ocurrencias("Cats, rats, bats, and hats.", "ats"), 4, "Expected output: 4") + self.assertEqual(count_occurrences("Cats, rats, bats, and hats.", "ats"), 4, "Expected output: 4") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/_sources/quiz/Quiz11_en.rst b/_sources/quiz/Quiz11_en.rst index 85f1ee4c7e..c8053416e1 100644 --- a/_sources/quiz/Quiz11_en.rst +++ b/_sources/quiz/Quiz11_en.rst @@ -13,14 +13,14 @@ Quiz - 11 .. activecode:: q11_1_en :nocodelens: - Develop the function ``verbo`` that receives a string ``s`` as a parameter. If the length of the string is at least 3, it should return the original string concatenated with ``"ing"`` at the end. If the string ``s`` already ends with ``"ing"``, concatenate the string ``"ly"``. If the length of the string is less than 3, it returns the original string. |br| |br| + Develop the function ``verb`` that receives a string ``s`` as a parameter. If the length of the string is at least 3, it should return the original string concatenated with ``"ing"`` at the end. If the string ``s`` already ends with ``"ing"``, concatenate the string ``"ly"``. If the length of the string is less than 3, it returns the original string. |br| |br| Examples: |br| - ``verbo("singing")`` -> ``"singingly"`` |br| - ``verbo("travel")`` -> ``"traveling"`` |br| - ``verbo("do")`` -> ``"do"`` |br| + ``verb("singing")`` -> ``"singingly"`` |br| + ``verb("travel")`` -> ``"traveling"`` |br| + ``verb("do")`` -> ``"do"`` |br| ~~~~ - def verbo(s): + def verb(s): @@ -31,13 +31,13 @@ Quiz - 11 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(verbo("hail"), "hailing", "Expected: hailing") - self.assertEqual(verbo("swiming"), "swimingly", "Expected: swimingly") - self.assertEqual(verbo("do"), "do", "Expected: do") - self.assertEqual(verbo("singing"), "singingly", "Expected: singingly") - self.assertEqual(verbo("travel"), "traveling", "Expected: traveling") - self.assertEqual(verbo("lly"), "llying", "Expected: llying") - self.assertEqual(verbo("ing"), "ingly", "Expected: ingly") + self.assertEqual(verb("hail"), "hailing", "Expected: hailing") + self.assertEqual(verb("swiming"), "swimingly", "Expected: swimingly") + self.assertEqual(verb("do"), "do", "Expected: do") + self.assertEqual(verb("singing"), "singingly", "Expected: singingly") + self.assertEqual(verb("travel"), "traveling", "Expected: traveling") + self.assertEqual(verb("lly"), "llying", "Expected: llying") + self.assertEqual(verb("ing"), "ingly", "Expected: ingly") myTests().main() @@ -48,15 +48,15 @@ Quiz - 11 .. activecode:: q11_2_en :nocodelens: - Develop the function ``no_es_malo`` that receives a string ``s`` as a parameter. The function must search for the first occurrence of the string ``"no es"`` and the last occurrence of the string ``"malo"`` or the string ``"mala"``, if either appears after the first one, replace ``"no es" ... "malo"`` or ``"no es" ... "mala"`` with the strings ``"es bueno"`` or ``"es buena"`` respectively, then return the result. |br| |br| + Develop the function ``is_not_bad`` that receives a string ``s`` as a parameter. The function must search for the first occurrence of the string ``"is not bad"`` and the last occurrence of the string ``"bad"`, if either appears after the first one, replace ``"is not" ... "bad"`` with the strings ``"is good"`` respectively, then return the result. |br| |br| Examples: |br| - ``no_es_malo("El té no es malo")`` -> ``"El té es bueno"`` |br| - ``no_es_malo("La película no es mala")`` -> ``"La película es buena"`` |br| - ``no_es_malo("El precio de esta casa no es para nada malo")`` -> ``"El precio de esta casa es bueno"`` |br| - ``no_es_malo("El teléfono es malo")`` -> ``"El teléfono es malo"`` |br| + ``is_not_bad("The tea is not bad")`` -> ``"The tea is good"`` |br| + ``is_not_bad("The movie is not bad")`` -> ``"The movie is good"`` |br| + ``is_not_bad("This house price is not that bad")`` -> ``"This house price is good"`` |br| + ``is_not_bad("The phone is bad")`` -> ``"The phone is bad"`` |br| ~~~~ - def no_es_malo(s): + def is_not_bad(s): @@ -68,36 +68,36 @@ Quiz - 11 def testOne(self): self.assertEqual( - no_es_malo("El televisor no es malo"), - "El televisor es bueno", - "Expected: El televisor es bueno" + is_not_bad("The tv is not bad"), + "The tv is good", + "Expected: The tv is good" ) self.assertEqual( - no_es_malo("El asado de la cena no es malo!"), - "El asado de la cena es bueno!", - "Expected: El asado de la cena es bueno!" + is_not_bad("The barbecue for launch is not bad"), + "The barbecue for launch is good", + "Expected: The barbecue for launch is good" ) self.assertEqual( - no_es_malo("El té no está caliente"), - "El té no está caliente", - "Expected: El té no está caliente" + is_not_bad("The tea is not hot"), + "The tea is not hot", + "Expected: The tea is not hot" ) self.assertEqual( - no_es_malo("La película no es mala"), - "La película es buena", - "Expected: La película es buena" + is_not_bad("The movie is not good"), + "The movie is good", + "Expected: The movie is good" ) - self.assertEqual(no_es_malo("no es para nada malo"), "es bueno", "Expected: es bueno") - self.assertEqual(no_es_malo("no es malo"), "es bueno", "Expected: es bueno") - self.assertEqual(no_es_malo("malo"), "malo", "Expected: malo") - self.assertEqual(no_es_malo("no"), "no", "Expected: no") - self.assertEqual(no_es_malo("NO"), "NO", "Expected: NO") - self.assertEqual(no_es_malo("MALO"), "MALO", "Expected: MALO") - self.assertEqual(no_es_malo("NO es MALO"), "NO es MALO", "Expected: NO es MALO") - self.assertEqual(no_es_malo("no es MALO"), "no es MALO", "Expected: no es MALO") - self.assertEqual(no_es_malo("NO es malo"), "NO es malo", "Expected: NO es malo") - self.assertEqual(no_es_malo("no es malo ni mala"), "es buena", "Expected: es buena") - self.assertEqual(no_es_malo("no es ni mala ni malo"), "es bueno", "Expected: es bueno") + self.assertEqual(is_not_bad("is not that bad"), "is good", "Expected: is good") + self.assertEqual(is_not_bad("is not bad"), "is good", "Expected: is ")good + self.assertEqual(is_not_bad("bad"), "bad", "Expected: bad") + self.assertEqual(is_not_bad("no"), "no", "Expected: no") + self.assertEqual(is_not_bad("NO"), "NO", "Expected: NO") + self.assertEqual(is_not_bad("BAD"), "BAD", "Expected: BAD") + self.assertEqual(is_not_bad("IS NOT BAD"), "IS NOT BAD", "Expected: IS NOT BAD") + self.assertEqual(is_not_bad("is not BAD), "is not BAD", "Expected: is not BAD") + self.assertEqual(is_not_bad("IS NOT bad"), "IS NOT bad", "Expected: IS NOT bad") + self.assertEqual(is_not_bad("is not bad"), "is good", "Expected: is good") + self.assertEqual(is_not_bad("is not bad"), "is good", "Expected: is good") myTests().main() @@ -108,14 +108,14 @@ Quiz - 11 .. activecode:: q11_3_en :nocodelens: - Develop the function ``inicio_final`` that receives two strings ``a`` and ``b``. The strings have to be divided into two, if either of the strings has an odd number of characters, the first half will be the longest substring (for example ``dog`` will be divided into: ``do`` and ``g``). Given the two strings, return a new string formed as follows ``a_start + b_start + a_end + b_end``. |br| |br| + Develop the function ``start_end`` that receives two strings ``a`` and ``b``. The strings have to be divided into two, if either of the strings has an odd number of characters, the first half will be the longest substring (for example ``dog`` will be divided into: ``do`` and ``g``). Given the two strings, return a new string formed as follows ``a_start + b_start + a_end + b_end``. |br| |br| Examples: |br| - ``inicio_final("abcd", "1234")`` -> ``"ab12cd34"`` |br| - ``inicio_final("abc", "1234")`` -> ``"ab12c34"`` |br| - ``inicio_final("abc", "123")`` -> ``"ab12c3"`` |br| + ``start_end("abcd", "1234")`` -> ``"ab12cd34"`` |br| + ``start_end("abc", "1234")`` -> ``"ab12c34"`` |br| + ``start_end("abc", "123")`` -> ``"ab12c3"`` |br| ~~~~ - def inicio_final(a, b): + def start_end(a, b): @@ -126,16 +126,16 @@ Quiz - 11 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(inicio_final("abcd", "xy"), "abxcdy", "Expected: abxcdy") - self.assertEqual(inicio_final("abcde", "xyz"), "abcxydez", "Expected: abcxydez") - self.assertEqual(inicio_final("a", "b"), "ab", "Expected: ab") - self.assertEqual(inicio_final("ac", "b"), "abc", "Expected: abc") - self.assertEqual(inicio_final("a", "bc"), "abc", "Expected: abc") - self.assertEqual(inicio_final("", ""), "", "Expected: ''") - self.assertEqual(inicio_final("a", ""), "a", "Expected: 'a'") - self.assertEqual(inicio_final("", "b"), "b", "Expected: 'b'") + self.assertEqual(start_end("abcd", "xy"), "abxcdy", "Expected: abxcdy") + self.assertEqual(start_end("abcde", "xyz"), "abcxydez", "Expected: abcxydez") + self.assertEqual(start_end("a", "b"), "ab", "Expected: ab") + self.assertEqual(start_end("ac", "b"), "abc", "Expected: abc") + self.assertEqual(start_end("a", "bc"), "abc", "Expected: abc") + self.assertEqual(start_end("", ""), "", "Expected: ''") + self.assertEqual(start_end("a", ""), "a", "Expected: 'a'") + self.assertEqual(start_end("", "b"), "b", "Expected: 'b'") self.assertEqual( - inicio_final("Kitten", "Donut"), + start_end("Kitten", "Donut"), "KitDontenut", "Expected: KitDontenut" ) @@ -149,13 +149,13 @@ Quiz - 11 .. activecode:: q11_4_en :nocodelens: - Develop the function ``cuantos_ceros`` that given a positive integer ``n``, returns the number of zeros at the end of the integer. |br| |br| + Develop the function ``how_many_zeros`` that given a positive integer ``n``, returns the number of zeros at the end of the integer. |br| |br| Examples: |br| - ``cuantos_ceros(10010)`` -> ``1`` |br| - ``cuantos_ceros(908007000)`` -> ``3`` |br| + ``how_many_zeros(10010)`` -> ``1`` |br| + ``how_many_zeros(908007000)`` -> ``3`` |br| ~~~~ - def cuantos_ceros(n): + def how_many_zeros(n): @@ -166,16 +166,16 @@ Quiz - 11 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(cuantos_ceros(10100100010000), 4, "Expected: 4") - self.assertEqual(cuantos_ceros(90000000000000000010), 1, "Expected: 1") - self.assertEqual(cuantos_ceros(10), 1, "Expected: 1") - self.assertEqual(cuantos_ceros(1050051222), 0, "Expected: 0") - self.assertEqual(cuantos_ceros(1010101010), 1, "Expected: 1") - self.assertEqual(cuantos_ceros(5000), 3, "Expected: 3") - self.assertEqual(cuantos_ceros(10000000000), 10, "Expected: 10") - self.assertEqual(cuantos_ceros(555), 0, "Expected: 0") - self.assertEqual(cuantos_ceros(1), 0, "Expected: 0") - self.assertEqual(cuantos_ceros(0), 0, "Expected: 0") + self.assertEqual(how_many_zeros(10100100010000), 4, "Expected: 4") + self.assertEqual(how_many_zeros(90000000000000000010), 1, "Expected: 1") + self.assertEqual(how_many_zeros(10), 1, "Expected: 1") + self.assertEqual(how_many_zeros(1050051222), 0, "Expected: 0") + self.assertEqual(how_many_zeros(1010101010), 1, "Expected: 1") + self.assertEqual(how_many_zeros(5000), 3, "Expected: 3") + self.assertEqual(how_many_zeros(10000000000), 10, "Expected: 10") + self.assertEqual(how_many_zeros(555), 0, "Expected: 0") + self.assertEqual(how_many_zeros(1), 0, "Expected: 0") + self.assertEqual(how_many_zeros(0), 0, "Expected: 0") myTests().main() @@ -186,14 +186,14 @@ Quiz - 11 .. activecode:: q11_5_en :nocodelens: - Develop the function ``contar_2`` that receives a positive integer ``n`` greater than 0. The function must return the number of times the digit 2 appears in the interval``[0, n-1]``. |br| |br| + Develop the function ``count_2`` that receives a positive integer ``n`` greater than 0. The function must return the number of times the digit 2 appears in the interval``[0, n-1]``. |br| |br| Examples: |br| - ``contar_2(20)`` -> ``2`` |br| - ``contar_2(5)`` -> ``1`` |br| - ``contar_2(1)`` -> ``0`` |br| + ``count_2(20)`` -> ``2`` |br| + ``count_2(5)`` -> ``1`` |br| + ``count_2(1)`` -> ``0`` |br| ~~~~ - def contar_2(n): + def count_2(n): @@ -204,11 +204,11 @@ Quiz - 11 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(contar_2(20), 2, "Expected: 2") - self.assertEqual(contar_2(1), 0, "Expected: 0") - self.assertEqual(contar_2(5), 1, "Expected: 1") - self.assertEqual(contar_2(999), 300, "Expected: 300") - self.assertEqual(contar_2(555), 216, "Expected: 216") + self.assertEqual(count_2(20), 2, "Expected: 2") + self.assertEqual(count_2(1), 0, "Expected: 0") + self.assertEqual(count_2(5), 1, "Expected: 1") + self.assertEqual(count_2(999), 300, "Expected: 300") + self.assertEqual(count_2(555), 216, "Expected: 216") myTests().main() @@ -219,17 +219,17 @@ Quiz - 11 .. activecode:: q11_6_en :nocodelens: - Develop the function ``inicio_potencia`` that receives a positive integer ``n`` greater than 0. The function must return the first power of 2 that starts with ``n``. |br| |br| + Develop the function ``start_power`` that receives a positive integer ``n`` greater than 0. The function must return the first power of 2 that starts with ``n``. |br| |br| Examples: |br| - ``inicio_potencia(65)`` -> ``16`` |br| + ``start_power(65)`` -> ``16`` |br| *Explanation*: for ``n = 65`` the power of ``2^16`` results in ``65536`` which contains ``n`` at the beginning. |br| |br| - ``inicio_potencia(4)`` -> ``2`` |br| + ``start_power(4)`` -> ``2`` |br| *Explanation*: for ``n = 4`` the power of ``2^2`` results in ``4`` which contains ``n`` at the beginning. |br| |br| - ``inicio_potencia(3)`` -> ``5`` |br| + ``start_power(3)`` -> ``5`` |br| *Explanation*: for ``n = 3`` the power of ``2^5`` results in ``32`` which contains ``n`` at the beginning. |br| ~~~~ - def inicio_potencia(n): + def start_power(n): @@ -240,14 +240,14 @@ Quiz - 11 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(inicio_potencia(7), 46, "Expected: 46") - self.assertEqual(inicio_potencia(3), 5, "Expected: 5") - self.assertEqual(inicio_potencia(133), 316, "Expected: 316") - self.assertEqual(inicio_potencia(1024), 10, "Expected: 10") - self.assertEqual(inicio_potencia(123), 90, "Expected: 90") - self.assertEqual(inicio_potencia(1), 0, "Expected: 0") - self.assertEqual(inicio_potencia(10), 10, "Expected: 10") - self.assertEqual(inicio_potencia(50), 102, "Expected: 102") + self.assertEqual(start_power(7), 46, "Expected: 46") + self.assertEqual(start_power(3), 5, "Expected: 5") + self.assertEqual(start_power(133), 316, "Expected: 316") + self.assertEqual(start_power(1024), 10, "Expected: 10") + self.assertEqual(start_power(123), 90, "Expected: 90") + self.assertEqual(start_power(1), 0, "Expected: 0") + self.assertEqual(start_power(10), 10, "Expected: 10") + self.assertEqual(start_power(50), 102, "Expected: 102") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/_sources/quiz/Quiz1_en.rst b/_sources/quiz/Quiz1_en.rst index 31f9a6274c..57c60131a7 100644 --- a/_sources/quiz/Quiz1_en.rst +++ b/_sources/quiz/Quiz1_en.rst @@ -17,7 +17,7 @@ Quiz - 1 Make a program that asks for two integer numbers and prints the sum of those two numbers. |br| ~~~~ - def suma(n, m): + def sum(n, m): ==== @@ -27,10 +27,10 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(suma(24, 42), 66, "Expected: 66") - self.assertEqual(suma(17, 13), 30, "Expected: 30") - self.assertEqual(suma(-11, 6), -5, "Expected: -5") - self.assertEqual(suma(0, 9), 9, "Expected: 9") + self.assertEqual(sum(24, 42), 66, "Expected: 66") + self.assertEqual(sum(17, 13), 30, "Expected: 30") + self.assertEqual(sum(-11, 6), -5, "Expected: -5") + self.assertEqual(sum(0, 9), 9, "Expected: 9") myTests().main() @@ -44,7 +44,7 @@ Quiz - 1 Write a program that reads a value in meters and shows it converted to millimeters. |br| ~~~~ - def metros_a_milimetros(n): + def meters_to_millimeters(n): ==== @@ -54,9 +54,9 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(metros_a_milimetros(1), 1000,"Expected: 1000") - self.assertEqual(metros_a_milimetros(0.2), 200,"Expected: 200") - self.assertEqual(metros_a_milimetros(30), 30000,"Expected: 30000") + self.assertEqual(meters_to_millimeters(1), 1000,"Expected: 1000") + self.assertEqual(meters_to_millimeters(0.2), 200,"Expected: 200") + self.assertEqual(meters_to_millimeters(30), 30000,"Expected: 30000") myTests().main() @@ -71,7 +71,7 @@ Quiz - 1 the user. Calculate the total number of seconds. |br| ~~~~ - def tiempo_en_segundos(dias, horas, minutos, segundos): + def time_in_seconds(dias, horas, minutos, segundos): ==== @@ -81,10 +81,10 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(tiempo_en_segundos(2, 5, 2, 5), 190925, "Expected: 190925") - self.assertEqual(tiempo_en_segundos(10, 89, 5, 0), 1184700, "Expected: 1184700") - self.assertEqual(tiempo_en_segundos(8, 0, 2, 0), 691320, "Expected: 691320") - self.assertEqual(tiempo_en_segundos(0, 5, 55, 6), 21306, "Expected: 21306") + self.assertEqual(time_in_seconds(2, 5, 2, 5), 190925, "Expected: 190925") + self.assertEqual(time_in_seconds(10, 89, 5, 0), 1184700, "Expected: 1184700") + self.assertEqual(time_in_seconds(8, 0, 2, 0), 691320, "Expected: 691320") + self.assertEqual(time_in_seconds(0, 5, 55, 6), 21306, "Expected: 21306") myTests().main() @@ -100,7 +100,7 @@ Quiz - 1 the increase and the new salary. |br| ~~~~ - def aumento(salario, porcentaje): + def rise(salary, percentage): #Return the values in a tuple like: return (increase, new_salary) @@ -111,10 +111,10 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(aumento(30500, 10), (3050, 33550), "Expected: (3050,33550)") - self.assertEqual(aumento(10400, 25), (2600, 13000), "Expected: (2600,13000)") - self.assertEqual(aumento(50100, 8), (4008, 54108), "Expected: (4008,54108)") - self.assertEqual(aumento(25000, 3), (750, 25750), "Expected: (750,25750)") + self.assertEqual(rise(30500, 10), (3050, 33550), "Expected: (3050,33550)") + self.assertEqual(rise(10400, 25), (2600, 13000), "Expected: (2600,13000)") + self.assertEqual(rise(50100, 8), (4008, 54108), "Expected: (4008,54108)") + self.assertEqual(rise(25000, 3), (750, 25750), "Expected: (750,25750)") myTests().main() @@ -129,7 +129,7 @@ Quiz - 1 Display the discount amount and the final price. |br| ~~~~ - def precio_con_descuento(precio, porcentaje): + def price_with_discount(precio, porcentaje): #Return the values in a tuple like: return (discount, final_price) @@ -140,10 +140,10 @@ Quiz - 1 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(precio_con_descuento(100100, 10), (10010, 90090), "Expected: (10010,90090)") - self.assertEqual(precio_con_descuento(20523, 4), (820.92, 19702.08), "Expected: (820.92,19702.08)") - self.assertEqual(precio_con_descuento(55566, 50), (27783, 27783), "Expected: (27783,27783)") - self.assertEqual(precio_con_descuento(75660, 24), (18158.4, 57501.6), "Expected: (18158.4,57501.6)") + self.assertEqual(price_with_discount(100100, 10), (10010, 90090), "Expected: (10010,90090)") + self.assertEqual(price_with_discount(20523, 4), (820.92, 19702.08), "Expected: (820.92,19702.08)") + self.assertEqual(price_with_discount(55566, 50), (27783, 27783), "Expected: (27783,27783)") + self.assertEqual(price_with_discount(75660, 24), (18158.4, 57501.6), "Expected: (18158.4,57501.6)") myTests().main() @@ -319,4 +319,4 @@ Quiz - 1 self.assertEqual(digits(), 301030, "Expected: 301030") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/_sources/quiz/Quiz2_en.rst b/_sources/quiz/Quiz2_en.rst index 6fba826f3c..482a004fa0 100644 --- a/_sources/quiz/Quiz2_en.rst +++ b/_sources/quiz/Quiz2_en.rst @@ -14,15 +14,15 @@ Quiz - 2 .. activecode:: q2_1_en :nocodelens: - Develop the function ``es_triangulo`` that receives three positive integers ``a``, ``b``, and ``c``. They represent the sides of a triangle. The function should verify that a triangle is formed with the given parameters. If the given parameters form a triangle, the function should return a string indicating its type, i.e., ``"Equilátero"``, ``"Isósceles"``, or ``"Escaleno"``, otherwise, the function should return the string, ``"No es triángulo"``.|br| + Develop the function ``is_triangle`` that receives three positive integers ``a``, ``b``, and ``c``. They represent the sides of a triangle. The function should verify that a triangle is formed with the given parameters. If the given parameters form a triangle, the function should return a string indicating its type, i.e., ``"Equilateral"``, ``"Isosceles"``, or ``"Escaleno"``, otherwise, the function should return the string, ``"Is not triangle"``.|br| **Note**: remember that it is not a triangle when the longest side is greater than or equal to the sum of the other two. |br| |br| Examples: |br| - ``es_triangulo(2, 2, 2)`` -> ``"Equilátero"`` |br| - ``es_triangulo(3, 2, 2)`` -> ``"Isósceles"`` |br| - ``es_triangulo(4, 2, 6)`` -> ``"No es triángulo"`` |br| - ``es_triangulo(2, 1, 8)`` -> ``"No es triángulo"`` |br| + ``is_triangle(2, 2, 2)`` -> ``"Equilateral"`` |br| + ``is_triangle(3, 2, 2)`` -> ``"Isosceles"`` |br| + ``is_triangle(4, 2, 6)`` -> ``"Is not triangle"`` |br| + ``is_triangle(2, 1, 8)`` -> ``"Is not triangle"`` |br| ~~~~ - def es_triangulo(a, b, c): + def is_triangle(a, b, c): ==== @@ -32,15 +32,15 @@ Quiz - 2 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(es_triangulo(2, 2, 2), "Equilátero", "Expected: Equilátero") - self.assertEqual(es_triangulo(2, 1, 2), "Isósceles", "Expected: Isósceles") - self.assertEqual(es_triangulo(2, 1, 3), "No es triángulo", "Expected: No es triángulo") - self.assertEqual(es_triangulo(2, 1, 8), "No es triángulo", "Expected: No es triángulo") - self.assertEqual(es_triangulo(4, 2, 1), "No es triángulo", "Expected: No es triángulo") - self.assertEqual(es_triangulo(4, 1000, 1000), "Isósceles", "Expected: Isósceles") - self.assertEqual(es_triangulo(10000, 10000, 10000), "Equilátero", "Expected: Equilátero") - self.assertEqual(es_triangulo(3, 2, 2), "Isósceles", "Expected: Isósceles") - self.assertEqual(es_triangulo(10000, 1, 9999), "No es triángulo", "Expected: No es triángulo") + self.assertEqual(is_triangle(2, 2, 2), "Equilateral", "Expected: Equilateral") + self.assertEqual(is_triangle(2, 1, 2), "Isosceles", "Expected: Isosceles") + self.assertEqual(is_triangle(2, 1, 3), "Is not triangle", "Expected: Is not triangle") + self.assertEqual(is_triangle(2, 1, 8), "Is not triangle", "Expected: Is not triangle") + self.assertEqual(is_triangle(4, 2, 1), "Is not triangle", "Expected: Is not triangle") + self.assertEqual(is_triangle(4, 1000, 1000), "Isosceles", "Expected: Isosceles") + self.assertEqual(is_triangle(10000, 10000, 10000), "Equilateral", "Expected: Equilateral") + self.assertEqual(is_triangle(3, 2, 2), "Isosceles", "Expected: Isosceles") + self.assertEqual(is_triangle(10000, 1, 9999), "Is not triangle", "Expected: Is not triangle") myTests().main() @@ -51,14 +51,14 @@ Quiz - 2 .. activecode:: q2_2_en :nocodelens: - Develop the function ``es_bisiesto`` that receives the parameter ``anio`` which is a positive integer greater than zero and represents a year. The function should verify if the given parameter is a leap year, therefore, it should return ``True`` if it is, or ``False`` otherwise. A year is a leap year if it is divisible by 400, or also if it is divisible by 4 but not divisible by 100. |br| |br| + Develop the function ``is_leap`` that receives the parameter ``year`` which is a positive integer greater than zero and represents a year. The function should verify if the given parameter is a leap year, therefore, it should return ``True`` if it is, or ``False`` otherwise. A year is a leap year if it is divisible by 400, or also if it is divisible by 4 but not divisible by 100. |br| |br| Examples: |br| - ``es_bisiesto(2014)`` -> ``False`` |br| - ``es_bisiesto(2016)`` -> ``True`` |br| - ``es_bisiesto(1900)`` -> ``False`` |br| - ``es_bisiesto(2000)`` -> ``True`` |br| + ``is_leap(2014)`` -> ``False`` |br| + ``is_leap(2016)`` -> ``True`` |br| + ``is_leap(1900)`` -> ``False`` |br| + ``is_leap(2000)`` -> ``True`` |br| ~~~~ - def es_bisiesto(anio): + def is_leap(year): ==== @@ -68,15 +68,15 @@ Quiz - 2 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(es_bisiesto(2000), True, "Expected: True") - self.assertEqual(es_bisiesto(2001), False, "Expected: False") - self.assertEqual(es_bisiesto(2020), True, "Expected: True") - self.assertEqual(es_bisiesto(2016), True, "Expected: True") - self.assertEqual(es_bisiesto(2400), True, "Expected: True") - self.assertEqual(es_bisiesto(1952), True, "Expected: True") - self.assertEqual(es_bisiesto(1900), False, "Expected: False") - self.assertEqual(es_bisiesto(2200), False, "Expected: False") - self.assertEqual(es_bisiesto(2100), False, "Expected: False") + self.assertEqual(is_leap(2000), True, "Expected: True") + self.assertEqual(is_leap(2001), False, "Expected: False") + self.assertEqual(is_leap(2020), True, "Expected: True") + self.assertEqual(is_leap(2016), True, "Expected: True") + self.assertEqual(is_leap(2400), True, "Expected: True") + self.assertEqual(is_leap(1952), True, "Expected: True") + self.assertEqual(is_leap(1900), False, "Expected: False") + self.assertEqual(is_leap(2200), False, "Expected: False") + self.assertEqual(is_leap(2100), False, "Expected: False") myTests().main() @@ -181,15 +181,15 @@ Quiz - 2 .. activecode:: q2_6_en :nocodelens: - An employee of a company receives a monthly gross salary calculated by the amount of hours worked multiplied by its value. From this ``salary``, the month's ``11%`` for taxes, ``8%`` for health insurance, and ``5%`` for payment to the union are deducted. Develop the function ``calcular_salario`` that receives a float ``valor_hora`` and an integer ``cantidad_horas`` that represent how much he earns per hour and the amount of hours worked during the month. The function must return a dictionary of the form: |br| + An employee of a company receives a monthly gross income calculated by the amount of hours worked multiplied by its value. From this ``income``, the month's ``11%`` for taxes, ``8%`` for medical insurance, and ``5%`` for payment to the union of workers are deducted. Develop the function ``calculate_income`` that receives a float ``hour_value`` and an integer ``ammount_value`` that represent how much he earns per hour and the amount of hours worked during the month. The function must return a dictionary of the form: |br| - ``{"salario_bruto": A, "impuestos": B,`` |br| ``"seguro_medico": C, "sindicato": E, "salario_neto": F}``. |br| + ``{"gross_income": A, "taxes": B,`` |br| ``"medical_insurance": C, "union_of_workers": E, "net_income": F}``. |br| Where A, B, C, and D represent the amount of money corresponding to each item. |br| |br| Examples: |br| - ``calcular_salario(15.0, 120)`` -> ``{"salario_bruto": 1800.00, "impuestos": 198.00,`` |br| ``"seguro_medico": 144.0, "sindicato": 90.0, "salario_neto": 1368.00}``. |br| + ``calculate_income(15.0, 120)`` -> ``{"gross_income": 1800.00, "taxes": 198.00,`` |br| ``"medical_insurance": 144.0, "union_of_workers": 90.0, "net_income": 1368.00}``. |br| ~~~~ - def calcular_salario(valor_hora, cantidad_horas): + def calculate_income(hour_value, ammount_value): ==== @@ -198,15 +198,15 @@ Quiz - 2 class myTests(TestCaseGui): - def get_expected_dictionary(self, salary): + def get_expected_dictionary(self, income): result = { - "salario_bruto": salary, - "impuestos": salary * 0.11, - "seguro_medico": salary * 0.08, - "sindicato": salary * 0.05, + "gross_income": income, + "taxes": income * 0.11, + "medical_insurance": income * 0.08, + "union_of_workers": income * 0.05, } - result["salario_neto"] = (salary - result["impuestos"] - - result["seguro_medico"] - result["sindicato"]) + result["net_income"] = (income - result["taxes"] - + result["medical_insurance"] - result["union_of_workers"]) return result def testOne(self): @@ -218,35 +218,35 @@ Quiz - 2 for test in range(test_numbers): hour = random.randint(min_hour, max_hour) price = round(random.uniform(min_price_hour, max_price_hour), 2) - salary = price * hour - expected = self.get_expected_dictionary(salary) - result = calcular_salario(price, hour) + income = price * hour + expected = self.get_expected_dictionary(income) + result = calculate_income(price, hour) current_test = test + 1 self.assertEqual( - round(result["salario_bruto"], 2), - round(expected["salario_bruto"], 2), - f"Test #{current_test} - Expected gross salary: {round(expected['salario_bruto'], 2)}", + round(result["gross_income"], 2), + round(expected["gross_income"], 2), + f"Test #{current_test} - Expected gross income: {round(expected['gross_income'], 2)}", ) self.assertEqual( - round(result["impuestos"], 2), - round(expected["impuestos"], 2), - f"Test #{current_test} - Expected taxes: {round(expected['impuestos'], 2)}", + round(result["taxes"], 2), + round(expected["taxes"], 2), + f"Test #{current_test} - Expected taxes: {round(expected['taxes'], 2)}", ) self.assertEqual( - round(result["seguro_medico"], 2), - round(expected["seguro_medico"], 2), - f"Test #{current_test} - Expected health insurance: {round(expected['seguro_medico'], 2)}", + round(result["medical_insurance"], 2), + round(expected["medical_insurance"], 2), + f"Test #{current_test} - Expected health insurance: {round(expected['medical_insurance'], 2)}", ) self.assertEqual( - round(result["sindicato"], 2), - round(expected["sindicato"], 2), - f"Test #{current_test} - Expected union payment: {round(expected['sindicato'], 2)}", + round(result["union_of_workers"], 2), + round(expected["union_of_workers"], 2), + f"Test #{current_test} - Expected union payment: {round(expected['union_of_workers'], 2)}", ) self.assertEqual( - round(result["salario_neto"], 2), - round(expected["salario_neto"], 2), - f"Test #{current_test} - Expected net salary: {round(expected['salario_neto'], 2)}", + round(result["net_income"], 2), + round(expected["net_income"], 2), + f"Test #{current_test} - Expected net income: {round(expected['net_income'], 2)}", ) @@ -258,16 +258,16 @@ Quiz - 2 .. activecode:: q2_7_en :nocodelens: - The paint sold at your trusted hardware store has a coverage of 1 liter per every 3 square meters and the paint is sold only in cans of 18 liters that cost each one ``80.00`` units. Develop the function ``puedo_pintar`` that receives an amount in square meters of an area to be painted as a positive integer ``area``. The function should return a tuple with the amount of cans of paint that need to be bought to cover the entire area, as well as their total price, that is, using the form ``(amount_cans, total_price)``. |br| + The paint sold at your trusted hardware store has a coverage of 1 liter per every 3 square meters and the paint is sold only in cans of 18 liters that cost each one ``80.00`` units. Develop the function ``can_paint`` that receives an amount in square meters of an area to be painted as a positive integer ``area``. The function should return a tuple with the amount of cans of paint that need to be bought to cover the entire area, as well as their total price, that is, using the form ``(amount_cans, total_price)``. |br| **Note**: only an integer number of cans of paint is sold. |br| |br| Examples: |br| - ``puedo_pintar(10)`` -> ``(1, 80.00)`` |br| - ``puedo_pintar(100)`` -> ``(2, 160.00)`` |br| - ``puedo_pintar(54)`` -> ``(1, 80.00)`` |br| - ``puedo_pintar(55)`` -> ``(2, 160.00)`` |br| + ``can_paint(10)`` -> ``(1, 80.00)`` |br| + ``can_paint(100)`` -> ``(2, 160.00)`` |br| + ``can_paint(54)`` -> ``(1, 80.00)`` |br| + ``can_paint(55)`` -> ``(2, 160.00)`` |br| ~~~~ - def puedo_pintar(area): + def can_paint(area): ==== from unittest.gui import TestCaseGui @@ -276,14 +276,14 @@ Quiz - 2 class myTests(TestCaseGui): def testOne(self): - self.assertEqual(puedo_pintar(10), (1, 80.00), "Expected: (1, 80.00)") - self.assertEqual(puedo_pintar(100), (2, 160.00), "Expected: (2, 160.00)") - self.assertEqual(puedo_pintar(54), (1, 80.00), "Expected: (1, 80.00)") - self.assertEqual(puedo_pintar(55), (2, 160.00), "Expected: (2, 160.00)") - self.assertEqual(puedo_pintar(1000), (19, 1520.00), "Expected: (19, 1520.00)") - self.assertEqual(puedo_pintar(500), (10, 800.00), "Expected: (10, 800.00)") - self.assertEqual(puedo_pintar(250), (5, 400.00), "Expected: (5, 400.00)") - self.assertEqual(puedo_pintar(125), (3, 240.00), "Expected: (3, 240.00)") + self.assertEqual(can_paint(10), (1, 80.00), "Expected: (1, 80.00)") + self.assertEqual(can_paint(100), (2, 160.00), "Expected: (2, 160.00)") + self.assertEqual(can_paint(54), (1, 80.00), "Expected: (1, 80.00)") + self.assertEqual(can_paint(55), (2, 160.00), "Expected: (2, 160.00)") + self.assertEqual(can_paint(1000), (19, 1520.00), "Expected: (19, 1520.00)") + self.assertEqual(can_paint(500), (10, 800.00), "Expected: (10, 800.00)") + self.assertEqual(can_paint(250), (5, 400.00), "Expected: (5, 400.00)") + self.assertEqual(can_paint(125), (3, 240.00), "Expected: (3, 240.00)") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/_sources/quiz/Quiz3_en.rst b/_sources/quiz/Quiz3_en.rst index b3a3cc187a..9b4fa4e949 100644 --- a/_sources/quiz/Quiz3_en.rst +++ b/_sources/quiz/Quiz3_en.rst @@ -44,8 +44,8 @@ Quiz - 3 :nocodelens: Indicate how to make change using the minimum number of bills. - Your algorithm should read the amount of the bill to be paid, ``cobro``, and the amount - paid, ``pago``, without taking into account the cents. |br| + Your algorithm should read the amount of the bill to be paid, ``payment``, and the amount + paid, ``pay``, without taking into account the cents. |br| Suppose the bills for change are 50, 20, 10, 5, 2 and 1, and that none of them is missing in the cash register. Return a list with the quantity of each bill that represents the change. |br| The first element of the list matches the quantity of 50, @@ -55,7 +55,7 @@ Quiz - 3 ``calculate_change(92, 100)`` -> [0,0,0,1,1,1] |br| ~~~~ - def calculate_change(cobro, pago): + def calculate_change(payment, pay): ==== @@ -165,4 +165,4 @@ Quiz - 3 self.assertEqual(invert_number(230), 32, "Expected: 32") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/_sources/quiz/Quiz4_en.rst b/_sources/quiz/Quiz4_en.rst index 7b8dd26aa4..d4832670f0 100644 --- a/_sources/quiz/Quiz4_en.rst +++ b/_sources/quiz/Quiz4_en.rst @@ -14,14 +14,14 @@ Quiz - 4 .. activecode:: q4_1_en :nocodelens: - Develop the function ``valores_extremos`` which takes the parameter ``numeros``, representing a list of **10** random numbers between 0-100. - The function should return a tuple ``(a, b)``, where a and b are the maximum and minimum values respectively of the ``numeros`` list. Solve the problem without using + Develop the function ``extreme_values`` which takes the parameter ``numbers``, representing a list of **10** random numbers between 0-100. + The function should return a tuple ``(a, b)``, where a and b are the maximum and minimum values respectively of the ``numbers`` list. Solve the problem without using the functions ``max`` nor ``min``. |br| |br| Example: |br| - ``valores_extremos([15, 48, 0, 27, 13, 62, 32, 57, 85, 18])`` -> ``(85, 0)`` |br| + ``extreme_values([15, 48, 0, 27, 13, 62, 32, 57, 85, 18])`` -> ``(85, 0)`` |br| ~~~~ - def valores_extremos(numeros): + def extreme_values(numbers): ==== @@ -31,21 +31,21 @@ Quiz - 4 class myTests(TestCaseGui): def testOne(self): - numeros = sample(range(100), 10) + numbers = sample(range(100), 10) self.assertEqual( - valores_extremos(numeros), (max(numeros), min(numeros)), f"Expected: ({max(numeros)}, {min(numeros)})" + extreme_values(numbers), (max(numbers), min(numbers)), f"Expected: ({max(numbers)}, {min(numbers)})" ) def testTwo(self): - numeros = sample(range(100), 10) + numbers = sample(range(100), 10) self.assertEqual( - valores_extremos(numeros), (max(numeros), min(numeros)), f"Expected: ({max(numeros)}, {min(numeros)})" + extreme_values(numbers), (max(numbers), min(numbers)), f"Expected: ({max(numbers)}, {min(numbers)})" ) def testThree(self): - numeros = sample(range(100), 10) + numbers = sample(range(100), 10) self.assertEqual( - valores_extremos(numeros), (max(numeros), min(numeros)), f"Expected: ({max(numeros)}, {min(numeros)})" + extreme_values(numbers), (max(numbers), min(numbers)), f"Expected: ({max(numbers)}, {min(numbers)})" ) @@ -57,12 +57,12 @@ Quiz - 4 .. activecode:: q4_2_en :nocodelens: - Develop the function ``pares_e_impares`` which takes the parameter ``numeros``. ``numeros`` represents a list of **20** random numbers between 1-100. + Develop the function ``even_and_odd`` which takes the parameter ``numbers``. ``numbers`` represents a list of **20** random numbers between 1-100. The function should return a tuple of lists of the form ``([even], [odd])``, where even and odd are lists of even and odd numbers that are - in ``numeros``, respectively. |br| |br| + in ``numbers``, respectively. |br| |br| ~~~~ - def pares_e_impares(numeros): + def even_and_odd(numbers): ==== @@ -72,27 +72,27 @@ Quiz - 4 class myTests(TestCaseGui): def testOne(self): - numeros = sample(range(1, 100), 20) + numbers = sample(range(1, 100), 20) self.assertEqual( - pares_e_impares(numeros), - ([n for n in numeros if n % 2 == 0], [n for n in numeros if n % 2 != 0]), - f"Expected: ({[n for n in numeros if n%2 == 0]}, {[n for n in numeros if n%2 != 0]})", + even_and_odd(numbers), + ([n for n in numbers if n % 2 == 0], [n for n in numbers if n % 2 != 0]), + f"Expected: ({[n for n in numbers if n%2 == 0]}, {[n for n in numbers if n%2 != 0]})", ) def testTwo(self): - numeros = sample(range(1, 100), 20) + numbers = sample(range(1, 100), 20) self.assertEqual( - pares_e_impares(numeros), - ([n for n in numeros if n % 2 == 0], [n for n in numeros if n % 2 != 0]), - f"Expected: ({[n for n in numeros if n%2 == 0]}, {[n for n in numeros if n%2 != 0]})", + even_and_odd(numbers), + ([n for n in numbers if n % 2 == 0], [n for n in numbers if n % 2 != 0]), + f"Expected: ({[n for n in numbers if n%2 == 0]}, {[n for n in numbers if n%2 != 0]})", ) def testThree(self): - numeros = sample(range(1, 100), 20) + numbers = sample(range(1, 100), 20) self.assertEqual( - pares_e_impares(numeros), - ([n for n in numeros if n % 2 == 0], [n for n in numeros if n % 2 != 0]), - f"Expected: ({[n for n in numeros if n%2 == 0]}, {[n for n in numeros if n%2 != 0]})", + even_and_odd(numbers), + ([n for n in numbers if n % 2 == 0], [n for n in numbers if n % 2 != 0]), + f"Expected: ({[n for n in numbers if n%2 == 0]}, {[n for n in numbers if n%2 != 0]})", ) @@ -104,13 +104,13 @@ Quiz - 4 .. activecode:: q4_3_en :nocodelens: - Develop the function ``intercalar_listas`` which takes two parameters, ``l1`` and ``l2``, representing lists of **10** random numbers between 1-100. + Develop the function ``collate_lists`` which takes two parameters, ``l1`` and ``l2``, representing lists of **10** random numbers between 1-100. The function should generate a third list composed of the elements of ``l1`` and ``l2`` interleaved. This third list will be returned. |br| |br| Example: |br| - ``intercalar_listas([1, 3, 5, .....], [2, 4, 6, ....])`` -> ``[1, 2, 3, 4, 5, 6, ....]`` |br| + ``collate_lists([1, 3, 5, .....], [2, 4, 6, ....])`` -> ``[1, 2, 3, 4, 5, 6, ....]`` |br| ~~~~ - def intercalar_listas(l1, l2): + def collate_lists(l1, l2): ==== @@ -123,7 +123,7 @@ Quiz - 4 l1 = sample(range(100), 10) l2 = sample(range(100), 10) self.assertEqual( - intercalar_listas(l1, l2), + collate_lists(l1, l2), [val for pair in zip(l1, l2) for val in pair], f"Expected: {[val for pair in zip(l1, l2) for val in pair]}", ) @@ -132,7 +132,7 @@ Quiz - 4 l1 = sample(range(100), 10) l2 = sample(range(100), 10) self.assertEqual( - intercalar_listas(l1, l2), + collate_lists(l1, l2), [val for pair in zip(l1, l2) for val in pair], f"Expected: {[val for pair in zip(l1, l2) for val in pair]}", ) @@ -146,7 +146,7 @@ Quiz - 4 .. activecode:: q4_4_en :nocodelens: - The function ``buscar_palabras`` will be passed the following ``texto`` as argument: |br| + The function ``search_for_words`` will be passed the following ``text`` as argument: |br| *"The Python Software Foundation and the global Python community welcome and encourage participation by everyone. Our community is based on mutual respect, tolerance, and encouragement, and we are working to help each other live up to these principles. We want our community to be more diverse: whoever you are, and whatever your background, we welcome you."* |br| @@ -155,7 +155,7 @@ Quiz - 4 and be careful with capitalization. |br| |br| ~~~~ - def buscar_palabras(texto): + def search_for_words(text): ==== @@ -174,7 +174,7 @@ Quiz - 4 for word in text.lower().replace(".", "").replace(",", "").split() if word[0] in "python" or word[-1] in "python" ] - self.assertEqual(buscar_palabras(text), res, f"Expected: {res}") + self.assertEqual(search_for_words(text), res, f"Expected: {res}") myTests().main() @@ -185,12 +185,12 @@ Quiz - 4 .. activecode:: q4_5_en :nocodelens: - Now you will develop the function ``buscar_palabras_2``, which will be passed the previous text as a parameter. Again you will separate the - text into words, just like you did in *Exercise 4*. This time, you should calculate the number of words within ``texto`` that have any + Now you will develop the function ``search_for_words_2``, which will be passed the previous text as a parameter. Again you will separate the + text into words, just like you did in *Exercise 4*. This time, you should calculate the number of words within ``text`` that have any of the letters in the string ``"python"``, and also have a length greater than 4 characters. |br| |br| ~~~~ - def buscar_palabras_2(texto): + def search_for_words_2(text): ==== @@ -203,7 +203,7 @@ Quiz - 4 encourage participation by everyone. Our community is based on mutual respect, tolerance, and encouragement, and we are working to help each other live up to these principles. We want our community to be more diverse: whoever you are, and whatever your background, we welcome you.""" - self.assertEqual(buscar_palabras_2(text), 24, "Expected: 24") + self.assertEqual(search_for_words_2(text), 24, "Expected: 24") - myTests().main() \ No newline at end of file + myTests().main() diff --git a/tests/test_quiz1.py b/tests/test_quiz1.py index 32b39efdbc..18753da6ed 100644 --- a/tests/test_quiz1.py +++ b/tests/test_quiz1.py @@ -28,7 +28,7 @@ def test_quiz1_1_en(page): # Do the exercise page.click("text=Exercise 1") - page.click("text=def suma(n, m):") + page.click("text=def sum(n, m):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") page.keyboard.type("return n+m") @@ -68,7 +68,7 @@ def test_quiz1_2_en(page): # Do the exercise page.click("text=Exercise 2") - page.click("text=def metros_a_milimetros(n):") + page.click("text=def meters_to_millimeters(n):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") page.keyboard.type("return n * 1000") diff --git a/tests/test_quiz10.py b/tests/test_quiz10.py index 95536be83e..077f95f513 100644 --- a/tests/test_quiz10.py +++ b/tests/test_quiz10.py @@ -22,7 +22,7 @@ def test_quiz10_3_en(page): # Do the exercise page.click("text=Exercise 3") - page.click("text=def remplazar_primer_caracter(s):") + page.click("text=def replace_first_character(s):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") page.keyboard.type("return s[0] + s[1:].replace(s[0], '*')") diff --git a/tests/test_quiz11.py b/tests/test_quiz11.py index 2a3813b171..adf3160391 100644 --- a/tests/test_quiz11.py +++ b/tests/test_quiz11.py @@ -35,7 +35,7 @@ def test_quiz11_1_en(page): page.goto("quiz/Quiz11_en.html") page.wait_for_load_state() - page.click("text=def verbo(s):") + page.click("text=def verb(s):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") diff --git a/tests/test_quiz2.py b/tests/test_quiz2.py index ac110d5e69..1726d7eafb 100644 --- a/tests/test_quiz2.py +++ b/tests/test_quiz2.py @@ -22,11 +22,11 @@ def test_quiz2_2_en(page): # Do the exercise page.click("text=Exercise 2") - page.click("text=def es_bisiesto(anio):") + page.click("text=def is_leap(year):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") page.keyboard.type( - "return anio % 4 == 0 and (anio % 100 != 0 or anio % 400 == 0)") + "return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)") # Run the exercise and check it passed all unit tests page.click("#q2_2_en >> *css=button >> text=Run") diff --git a/tests/test_quiz3.py b/tests/test_quiz3.py index 2e3865222b..d0a515d749 100644 --- a/tests/test_quiz3.py +++ b/tests/test_quiz3.py @@ -39,7 +39,7 @@ def test_quiz3_2_en(page): # Do the exercise page.click("text=Exercise 2") - page.click("text=def calculate_change(cobro, pago):") + page.click("text=def calculate_change(payment, pay):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") diff --git a/tests/test_quiz4.py b/tests/test_quiz4.py index 23eb8626ac..0c5caca7f3 100644 --- a/tests/test_quiz4.py +++ b/tests/test_quiz4.py @@ -21,7 +21,7 @@ def test_quiz4_en(page): page.goto("quiz/Quiz4_en.html") # Do the exercise - page.click("text=def valores_extremos(numeros):") + page.click("text=def extreme_values(numbers):") page.keyboard.press("ArrowDown") page.keyboard.press("Tab") page.keyboard.type("return (max(numeros), min(numeros))")