diff --git a/_sources/challenges/BasicExercises/Reto06.rst b/_sources/challenges/BasicExercises/Reto06.rst new file mode 100644 index 0000000000..af6f81991c --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto06.rst @@ -0,0 +1,106 @@ +======== +String-1 +======== + + +.. tabbed:: quiz1 + + .. tab:: Ejercicio 1 + + .. activecode:: q1_1_ees + :nocodelens: + + Dado un entero count que representa el número de donuts, devuelve una cadena en la forma 'Número de donuts: ', donde es el número pasado. Sin embargo, si count es 10 o más, entonces usa la palabra 'muchos' en lugar del número real. + + ~~~~ + def donuts(count): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(donuts(4), 'Número de donuts: 4', "Esperado: 'Número de donuts: 4'") + self.assertEqual(donuts(9), 'Número de donuts: 9', "Esperado: 'Número de donuts: 9'") + self.assertEqual(donuts(10), 'Número de donuts: muchos', "Esperado: 'Número de donuts: muchos'") + self.assertEqual(donuts(99), 'Número de donuts: muchos', "Esperado: 'Número de donuts: muchos'") + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q1_2_ees + :nocodelens: + + Dada una cadena s, devuelve una cadena hecha de los dos primeros y los dos últimos caracteres de la cadena original, por lo que 'spring' produce 'spng'. Sin embargo, si la longitud de la cadena es menor que 2, devuelve en su lugar una cadena vacía. + + ~~~~ + def both_ends(s): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(both_ends('spring'), 'spng', "Esperado: 'spng'") + self.assertEqual(both_ends('Hello'), 'Helo', "Esperado: 'Helo'") + self.assertEqual(both_ends('a'), '', "Esperado: ''") + self.assertEqual(both_ends('xyz'), 'xyyz', "Esperado: 'xyyz'") + + myTests().main() + + .. tab:: Ejercicio 3 + + .. activecode:: q1_3_ees + :nocodelens: + + Dada una cadena s, devuelve una cadena donde todas las ocurrencias de su primer carácter han sido cambiadas por '*', excepto el primer carácter en sí. + + ~~~~ + def fix_start(s): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(fix_start('babble'), 'ba**le', "Esperado: 'ba**le'") + self.assertEqual(fix_start('aardvark'), 'a*rdv*rk', "Esperado: 'a*rdv*rk'") + self.assertEqual(fix_start('google'), 'goo*le', "Esperado: 'goo*le'") + self.assertEqual(fix_start('donut'), 'donut', "Esperado: 'donut'") + + myTests().main() + + .. tab:: Ejercicio 4 + + .. activecode:: q1_4_ees + :nocodelens: + + Dadas las cadenas a y b, devuelve una sola cadena con a y b separadas por un espacio ' ', excepto que intercambia los primeros 2 caracteres de cada cadena. + + ~~~~ + def mix_up(a, b): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(mix_up('mix', 'pod'), 'pox mid', "Esperado: 'pox mid'") + self.assertEqual(mix_up('dog', 'dinner'), 'dig donner', "Esperado: 'dig donner'") + self.assertEqual(mix_up('gnash', 'sport'), 'spash gnort', "Esperado: 'spash gnort'") + self.assertEqual(mix_up('pezzy', 'firm'), 'fizzy perm', "Esperado: 'fizzy perm'") + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto06_en.rst b/_sources/challenges/BasicExercises/Reto06_en.rst new file mode 100644 index 0000000000..b38a9acac5 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto06_en.rst @@ -0,0 +1,107 @@ +======== +String-1 +======== + + +.. tabbed:: quiz1 + + .. tab:: Exercise 1 + + .. activecode:: q1_1_reto6_ + :nocodelens: + + Given an int count of a number of donuts, return a string of the form 'Number of donuts: ', where is the number passed in. However, if the count is 10 or more, then use the word 'many' instead of the actual count. + + ~~~~ + def donuts(count): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(donuts(4), 'Number of donuts: 4', "Expected: 'Number of donuts: 4'") + self.assertEqual(donuts(9), 'Number of donuts: 9', "Expected: 'Number of donuts: 9'") + self.assertEqual(donuts(10), 'Number of donuts: many', "Expected: 'Number of donuts: many'") + self.assertEqual(donuts(99), 'Number of donuts: many', "Expected: 'Number of donuts: many'") + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q1_2_an + :nocodelens: + + Given a string s, return a string made of the first 2 and the last 2 chars of the original string, so 'spring' yields 'spng'. However, if the string length is less than 2, return instead the empty string. + + ~~~~ + def both_ends(s): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(both_ends('spring'), 'spng', "Expected: 'spng'") + self.assertEqual(both_ends('Hello'), 'Helo', "Expected: 'Helo'") + self.assertEqual(both_ends('a'), '', "Expected: ''") + self.assertEqual(both_ends('xyz'), 'xyyz', "Expected: 'xyyz'") + + myTests().main() + + .. tab:: Exercise 3 + + .. activecode:: q1_3_an + :nocodelens: + + Given a string s, return a string where all occurrences of its first char have been changed to '*', except do not change the first char itself. + + ~~~~ + def fix_start(s): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(fix_start('babble'), 'ba**le', "Expected: 'ba**le'") + self.assertEqual(fix_start('aardvark'), 'a*rdv*rk', "Expected: 'a*rdv*rk'") + self.assertEqual(fix_start('google'), 'goo*le', "Expected: 'goo*le'") + self.assertEqual(fix_start('donut'), 'donut', "Expected: 'donut'") + + myTests().main() + + .. tab:: Exercise 4 + + .. activecode:: q1_4_an + :nocodelens: + + Given strings a and b, return a single string with a and b separated by a space ' ', except swap the first 2 chars of each string. + + ~~~~ + def mix_up(a, b): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(mix_up('mix', 'pod'), 'pox mid', "Expected: 'pox mid'") + self.assertEqual(mix_up('dog', 'dinner'), 'dig donner', "Expected: 'dig donner'") + self.assertEqual(mix_up('gnash', 'sport'), 'spash gnort', "Expected: 'spash gnort'") + self.assertEqual(mix_up('pezzy', 'firm'), 'fizzy perm', "Expected: 'fizzy perm'") + + myTests().main() + diff --git a/_sources/challenges/BasicExercises/Reto07.rst b/_sources/challenges/BasicExercises/Reto07.rst new file mode 100644 index 0000000000..6be1661383 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto07.rst @@ -0,0 +1,78 @@ +======== +String-2 +======== + +.. tabbed:: quiz2 + + .. tab:: Ejercicio 1 + + .. activecode:: q2_1_hes + :nocodelens: + + Dada una cadena, si su longitud es al menos 3, agrega 'ing' al final. A menos que ya termine en 'ing', en cuyo caso agrega 'ly' en su lugar. Si la longitud de la cadena es menor que 3, déjala sin cambios. Devuelve la cadena resultante. + + ~~~~ + def verbing(s): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(verbing('saludo'), 'saludando', "Esperado: 'saludando'") + self.assertEqual(verbing('nadando'), 'nadando', "Esperado: 'nadando'") + self.assertEqual(verbing('ir'), 'ir', "Esperado: 'ir'") + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q2_2_hes + :nocodelens: + + Dada una cadena, encuentra la primera aparición de la subcadena 'not' y 'bad'. Si 'bad' sigue a 'not', reemplaza toda la subcadena 'not'...'bad' con 'bueno'. Devuelve la cadena resultante. Entonces '¡Esta cena no es tan mala!' produce: '¡Esta cena es buena!' + + ~~~~ + def not_bad(s): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(not_bad('Esta película no está tan mal'), 'Esta película es buena', "Esperado: 'Esta película es buena'") + self.assertEqual(not_bad('Esta cena no es tan mala!'), 'Esta cena es buena!', "Esperado: 'Esta cena es buena!'") + self.assertEqual(not_bad('Este té no está caliente'), 'Este té no está caliente', "Esperado: 'Este té no está caliente'") + self.assertEqual(not_bad("Es malo pero no"), "Es malo pero no", "Esperado: 'Es malo pero no'") + + myTests().main() + + .. tab:: Ejercicio 3 + + .. activecode:: q2_3_hes + :nocodelens: + + Considera dividir una cadena en dos mitades. Si la longitud es par, las mitades delanteras y traseras tienen la misma longitud. Si la longitud es impar, diremos que el carácter extra va en la mitad delantera. Por ejemplo, 'abcde', la mitad delantera es 'abc', la mitad trasera 'de'. Dadas 2 cadenas, a y b, devuelve una cadena de la forma a-mitad-delantera + b-mitad-delantera + a-mitad-trasera + b-mitad-trasera. + + ~~~~ + def front_back(a, b): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(front_back('abcd', 'xy'), 'abxcdy', "Esperado: 'abxcdy'") + self.assertEqual(front_back('abcde', 'xyz'), 'abcxydez', "Esperado: 'abcxydez'") + self.assertEqual(front_back('Gatito', 'Rosquilla'), 'GatRosquitinilloa', "Esperado: 'GatRosquitinilloa'") + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto07_en.rst b/_sources/challenges/BasicExercises/Reto07_en.rst new file mode 100644 index 0000000000..34ed56fdaa --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto07_en.rst @@ -0,0 +1,79 @@ +======== +String-2 +======== + + +.. tabbed:: quiz2 + + .. tab:: Exercise 1 + + .. activecode:: q2_1_reto7_ + :nocodelens: + + Given a string, if its length is at least 3, add 'ing' to its end. Unless it already ends in 'ing', in which case add 'ly' instead. If the string length is less than 3, leave it unchanged. Return the resulting string. + + ~~~~ + def verbing(s): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(verbing('hail'), 'hailing', "Expected: 'hailing'") + self.assertEqual(verbing('swiming'), 'swimingly', "Expected: 'swimingly'") + self.assertEqual(verbing('do'), 'do', "Expected: 'do'") + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q2_2_bn + :nocodelens: + + Given a string, find the first appearance of the substring 'not' and 'bad'. If the 'bad' follows the 'not', replace the whole 'not'...'bad' substring with 'good'. Return the resulting string. So 'This dinner is not that bad!' yields: 'This dinner is good!' + + ~~~~ + def not_bad(s): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(not_bad('This movie is not so bad'), 'This movie is good', "Expected: 'This movie is good'") + self.assertEqual(not_bad('This dinner is not that bad!'), 'This dinner is good!', "Expected: 'This dinner is good!'") + self.assertEqual(not_bad('This tea is not hot'), 'This tea is not hot', "Expected: 'This tea is not hot'") + self.assertEqual(not_bad("It's bad yet not"), "It's bad yet not", "Expected: 'It's bad yet not'") + + myTests().main() + + .. tab:: Exercise 3 + + .. activecode:: q2_3_bn + :nocodelens: + + Consider dividing a string into two halves. If the length is even, the front and back halves are the same length. If the length is odd, we'll say that the extra char goes in the front half. e.g. 'abcde', the front half is 'abc', the back half 'de'. Given 2 strings, a and b, return a string of the form a-front + b-front + a-back + b-back. + + ~~~~ + def front_back(a, b): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(front_back('abcd', 'xy'), 'abxcdy', "Expected: 'abxcdy'") + self.assertEqual(front_back('abcde', 'xyz'), 'abcxydez', "Expected: 'abcxydez'") + self.assertEqual(front_back('Kitten', 'Donut'), 'KitDontenut', "Expected: 'KitDontenut'") + + myTests().main() \ No newline at end of file diff --git a/_sources/challenges/BasicExercises/Reto08.rst b/_sources/challenges/BasicExercises/Reto08.rst new file mode 100644 index 0000000000..664b83ab82 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto08.rst @@ -0,0 +1,77 @@ +====== +List-1 +====== + +.. tabbed:: quiz1 + + .. tab:: Ejercicio 1 + + .. activecode:: q1_1_lln + :nocodelens: + + Dada una lista de cadenas, devuelve el recuento del número de cadenas donde la longitud de la cadena es de 2 o más y los primeros y últimos caracteres de la cadena son iguales. + + ~~~~ + def match_ends(words): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3, "Esperado: 3") + self.assertEqual(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2, "Esperado: 2") + self.assertEqual(match_ends(['aaa', 'be', 'abc', 'hello']), 1, "Esperado: 1") + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q1_2_lln + :nocodelens: + + Dada una lista de cadenas, devuelve una lista con las cadenas en orden ordenado, excepto agrupa todas las cadenas que comienzan con 'x' primero. + + ~~~~ + def front_x(words): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), ['xaa', 'xzz', 'axx', 'bbb', 'ccc'], "Esperado: ['xaa', 'xzz', 'axx', 'bbb', 'ccc']") + self.assertEqual(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']), ['xaa', 'xcc', 'aaa', 'bbb', 'ccc'], "Esperado: ['xaa', 'xcc', 'aaa', 'bbb', 'ccc']") + self.assertEqual(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']), ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'], "Esperado: ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']") + + myTests().main() + + .. tab:: Ejercicio 3 + + .. activecode:: q1_3_lln + :nocodelens: + + Dada una lista de tuplas no vacías, devuelve una lista ordenada en orden creciente por el último elemento de cada tupla. + + ~~~~ + def sort_last(tuples): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(sort_last([(1, 3), (3, 2), (2, 1)]), [(2, 1), (3, 2), (1, 3)], "Esperado: [(2, 1), (3, 2), (1, 3)]") + self.assertEqual(sort_last([(2, 3), (1, 2), (3, 1)]), [(3, 1), (1, 2), (2, 3)], "Esperado: [(3, 1), (1, 2), (2, 3)]") + self.assertEqual(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]), [(2, 2), (1, 3), (3, 4, 5), (1, 7)], "Esperado: [(2, 2), (1, 3), (3, 4, 5), (1, 7)]") + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto08_en.rst b/_sources/challenges/BasicExercises/Reto08_en.rst new file mode 100644 index 0000000000..649bc868ff --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto08_en.rst @@ -0,0 +1,77 @@ +====== +List-1 +====== + +.. tabbed:: quiz1 + + .. tab:: Exercise 1 + + .. activecode:: q1_1_reto8_ + :nocodelens: + + Given a list of strings, return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same. + + ~~~~ + def match_ends(words): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3, "Expected: 3") + self.assertEqual(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2, "Expected: 2") + self.assertEqual(match_ends(['aaa', 'be', 'abc', 'hello']), 1, "Expected: 1") + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q1_2_cn + :nocodelens: + + Given a list of strings, return a list with the strings in sorted order, except group all the strings that begin with 'x' first. + + ~~~~ + def front_x(words): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), ['xaa', 'xzz', 'axx', 'bbb', 'ccc'], "Expected: ['xaa', 'xzz', 'axx', 'bbb', 'ccc']") + self.assertEqual(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']), ['xaa', 'xcc', 'aaa', 'bbb', 'ccc'], "Expected: ['xaa', 'xcc', 'aaa', 'bbb', 'ccc']") + self.assertEqual(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']), ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'], "Expected: ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']") + + myTests().main() + + .. tab:: Exercise 3 + + .. activecode:: q1_3_cn + :nocodelens: + + Given a list of non-empty tuples, return a list sorted in increasing order by the last element in each tuple. + + ~~~~ + def sort_last(tuples): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(sort_last([(1, 3), (3, 2), (2, 1)]), [(2, 1), (3, 2), (1, 3)], "Expected: [(2, 1), (3, 2), (1, 3)]") + self.assertEqual(sort_last([(2, 3), (1, 2), (3, 1)]), [(3, 1), (1, 2), (2, 3)], "Expected: [(3, 1), (1, 2), (2, 3)]") + self.assertEqual(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]), [(2, 2), (1, 3), (3, 4, 5), (1, 7)], "Expected: [(2, 2), (1, 3), (3, 4, 5), (1, 7)]") + + myTests().main() \ No newline at end of file diff --git a/_sources/challenges/BasicExercises/Reto09.rst b/_sources/challenges/BasicExercises/Reto09.rst new file mode 100644 index 0000000000..8c0354211a --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto09.rst @@ -0,0 +1,53 @@ +====== +List-2 +====== + +.. tabbed:: quiz2 + + .. tab:: Ejercicio 1 + + .. activecode:: q2_1_rrn + :nocodelens: + + Dada una lista de números, devuelve una lista donde todos los elementos adyacentes iguales se han reducido a un solo elemento, por lo que [1, 2, 2, 3] devuelve [1, 2, 3]. Puedes crear una nueva lista o modificar la lista pasada como argumento. + + ~~~~ + def remove_adjacent(nums): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(remove_adjacent([1, 2, 2, 3]), [1, 2, 3], "Esperado: [1, 2, 3]") + self.assertEqual(remove_adjacent([2, 2, 3, 3, 3]), [2, 3], "Esperado: [2, 3]") + self.assertEqual(remove_adjacent([]), [], "Esperado: []") + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q2_2_rrn + :nocodelens: + + Dadas dos listas ordenadas en orden creciente, crea y devuelve una lista fusionada de todos los elementos en orden ordenado. Puedes modificar las listas pasadas como argumento. Idealmente, la solución debería funcionar en tiempo "lineal", haciendo un solo recorrido de ambas listas. + + ~~~~ + def linear_merge(list1, list2): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(linear_merge(['aa', 'xx', 'zz'], ['bb', 'cc']), ['aa', 'bb', 'cc', 'xx', 'zz'], "Esperado: ['aa', 'bb', 'cc', 'xx', 'zz']") + self.assertEqual(linear_merge(['aa', 'xx'], ['bb', 'cc', 'zz']), ['aa', 'bb', 'cc', 'xx', 'zz'], "Esperado: ['aa', 'bb', 'cc', 'xx', 'zz']") + self.assertEqual(linear_merge(['aa', 'aa'], ['aa', 'bb', 'bb']), ['aa', 'aa', 'aa', 'bb', 'bb'], "Esperado: ['aa', 'aa', 'aa', 'bb', 'bb']") + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto09_en.rst b/_sources/challenges/BasicExercises/Reto09_en.rst new file mode 100644 index 0000000000..329e388df0 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto09_en.rst @@ -0,0 +1,53 @@ +====== +List-2 +====== + +.. tabbed:: quiz2 + + .. tab:: Exercise 1 + + .. activecode:: q2_1_reto9_ + :nocodelens: + + Given a list of numbers, return a list where all adjacent == elements have been reduced to a single element, so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or modify the passed in list. + + ~~~~ + def remove_adjacent(nums): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(remove_adjacent([1, 2, 2, 3]), [1, 2, 3], "Expected: [1, 2, 3]") + self.assertEqual(remove_adjacent([2, 2, 3, 3, 3]), [2, 3], "Expected: [2, 3]") + self.assertEqual(remove_adjacent([]), [], "Expected: []") + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q2_2_dn + :nocodelens: + + Given two lists sorted in increasing order, create and return a merged list of all the elements in sorted order. You may modify the passed in lists. Ideally, the solution should work in "linear" time, making a single pass of both lists. + + ~~~~ + def linear_merge(list1, list2): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + def testOne(self): + self.assertEqual(linear_merge(['aa', 'xx', 'zz'], ['bb', 'cc']), ['aa', 'bb', 'cc', 'xx', 'zz'], "Expected: ['aa', 'bb', 'cc', 'xx', 'zz']") + self.assertEqual(linear_merge(['aa', 'xx'], ['bb', 'cc', 'zz']), ['aa', 'bb', 'cc', 'xx', 'zz'], "Expected: ['aa', 'bb', 'cc', 'xx', 'zz']") + self.assertEqual(linear_merge(['aa', 'aa'], ['aa', 'bb', 'bb']), ['aa', 'aa', 'aa', 'bb', 'bb'], "Expected: ['aa', 'aa', 'aa', 'bb', 'bb']") + + myTests().main() \ No newline at end of file diff --git a/_sources/challenges/BasicExercises/Reto10.rst b/_sources/challenges/BasicExercises/Reto10.rst new file mode 100644 index 0000000000..846e65279d --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto10.rst @@ -0,0 +1,50 @@ +========================================= +Ejercicio de Conteo de Palabras en Python +========================================= + + +.. tabbed:: quiz3 + + .. tab:: Ejercicio 1 + + .. activecode:: q3_1_eewcn + :nocodelens: + + Para la bandera --count, implementa una función print_words(filename) que cuente cuántas veces aparece cada palabra en el texto e imprima: palabra1 contador1, palabra2 contador2, ... Imprime la lista anterior en orden ordenado por palabra (Python ordenará la puntuación para que aparezca antes que las letras, eso está bien). Almacena todas las palabras en minúsculas, así que 'The' y 'the' cuentan como la misma palabra. + + ~~~~ + def print_words(filename): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Agrega tus pruebas aquí + pass + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q3_2_eewcn + :nocodelens: + + Para la bandera --topcount, implementa una función print_top(filename) que es similar a print_words() pero que imprime solo las 20 palabras más comunes ordenadas de manera que la palabra más común sea la primera, luego la siguiente palabra más común, y así sucesivamente. + + ~~~~ + def print_top(filename): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Agrega tus pruebas aquí + pass + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto10_en.rst b/_sources/challenges/BasicExercises/Reto10_en.rst new file mode 100644 index 0000000000..810f47fb26 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto10_en.rst @@ -0,0 +1,50 @@ +========================= +Python Wordcount Exercise +========================= + + +.. tabbed:: quiz3 + + .. tab:: Exercise 1 + + .. activecode:: q3_1_reto10_ + :nocodelens: + + For the --count flag, implement a print_words(filename) function that counts how often each word appears in the text and prints: word1 count1, word2 count2, ... Print the above list in order sorted by word (python will sort punctuation to come before letters -- that's fine). Store all the words as lowercase, so 'The' and 'the' count as the same word. + + ~~~~ + def print_words(filename): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Add your tests here + pass + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q3_2_wcn + :nocodelens: + + For the --topcount flag, implement a print_top(filename) which is similar to print_words() but which prints just the top 20 most common words sorted so the most common word is first, then the next most common, and so on. + + ~~~~ + def print_top(filename): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Add your tests here + pass + + myTests().main() \ No newline at end of file diff --git a/_sources/challenges/BasicExercises/Reto11.rst b/_sources/challenges/BasicExercises/Reto11.rst new file mode 100644 index 0000000000..7786639e49 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto11.rst @@ -0,0 +1,50 @@ +====================== +Python Ejercicio Mimic +====================== + + +.. tabbed:: quiz2 + + .. tab:: Ejercicio 1 + + .. activecode:: q4_1_eemcn + :nocodelens: + + Construye un diccionario "mimic" que mapee cada palabra que aparece en el archivo a una lista de todas las palabras que inmediatamente siguen a esa palabra en el archivo. La lista de palabras puede estar en cualquier orden y debe incluir duplicados. + + ~~~~ + def mimic_dict(filename): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Agrega tus pruebas aquí + pass + + myTests().main() + + .. tab:: Ejercicio 2 + + .. activecode:: q4_2_eemcn + :nocodelens: + + Dado un diccionario mimic y una palabra de inicio, imprime 200 palabras aleatorias. + + ~~~~ + def print_mimic(mimic_dict, word): + # +++tu código aquí+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Agrega tus pruebas aquí + pass + + myTests().main() diff --git a/_sources/challenges/BasicExercises/Reto11_en.rst b/_sources/challenges/BasicExercises/Reto11_en.rst new file mode 100644 index 0000000000..ece6f9ab57 --- /dev/null +++ b/_sources/challenges/BasicExercises/Reto11_en.rst @@ -0,0 +1,49 @@ +===================== +Python Mimic Exercise +===================== + +.. tabbed:: quiz2 + + .. tab:: Exercise 1 + + .. activecode:: q4_1_reto11_ + :nocodelens: + + Build a "mimic" dict that maps each word that appears in the file to a list of all the words that immediately follow that word in the file. The list of words can be in any order and should include duplicates. + + ~~~~ + def mimic_dict(filename): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Add your tests here + pass + + myTests().main() + + .. tab:: Exercise 2 + + .. activecode:: q4_2_mcn + :nocodelens: + + Given mimic dict and start word, prints 200 random words. + + ~~~~ + def print_mimic(mimic_dict, word): + # +++your code here+++ + return + + + ==== + from unittest.gui import TestCaseGui + + class myTests(TestCaseGui): + # Add your tests here + pass + + myTests().main() \ No newline at end of file diff --git a/_sources/challenges/BasicExercises/toctree.rst b/_sources/challenges/BasicExercises/toctree.rst new file mode 100644 index 0000000000..ed6545a4ae --- /dev/null +++ b/_sources/challenges/BasicExercises/toctree.rst @@ -0,0 +1,23 @@ +=================== +Básico - Ejercicios +=================== + + +.. image:: ../../lectures/img/TWP10_001.jpeg + :height: 14.832cm + :width: 9.2cm + :align: center + :alt: + + +.. toctree:: + :caption: Contenido + :maxdepth: 1 + :numbered: + + Reto06.rst + Reto07.rst + Reto08.rst + Reto09.rst + Reto10.rst + Reto11.rst diff --git a/_sources/challenges/BasicExercises/toctree_en.rst b/_sources/challenges/BasicExercises/toctree_en.rst new file mode 100644 index 0000000000..3d0db2843e --- /dev/null +++ b/_sources/challenges/BasicExercises/toctree_en.rst @@ -0,0 +1,23 @@ +================= +Basic - Exercises +================= + + +.. image:: ../../lectures/img/TWP10_001.jpeg + :height: 14.832cm + :width: 9.2cm + :align: center + :alt: + + +.. toctree:: + :caption: Contenido + :maxdepth: 1 + :numbered: + + Reto06_en.rst + Reto07_en.rst + Reto08_en.rst + Reto09_en.rst + Reto10_en.rst + Reto11_en.rst diff --git a/_sources/index_en.rst b/_sources/index_en.rst index 07582b56c2..3fa1af5c1b 100644 --- a/_sources/index_en.rst +++ b/_sources/index_en.rst @@ -54,6 +54,7 @@ Contents: challenges/Reto03_en.rst challenges/Reto04_en.rst challenges/Reto05_en.rst + challenges/BasicExercises/toctree_en.rst diff --git a/_sources/index_es.rst b/_sources/index_es.rst index ecf1551c24..5e3dd7a2f1 100644 --- a/_sources/index_es.rst +++ b/_sources/index_es.rst @@ -54,3 +54,4 @@ Contenidos: challenges/Reto03.rst challenges/Reto04.rst challenges/Reto05.rst + challenges/BasicExercises/toctree