Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Basic exercises #340

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions _sources/challenges/BasicExercises/Reto06.rst
Original file line number Diff line number Diff line change
@@ -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: <count>', donde <count> 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 '<a> <b>', 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()
107 changes: 107 additions & 0 deletions _sources/challenges/BasicExercises/Reto06_en.rst
Original file line number Diff line number Diff line change
@@ -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: <count>', where <count> 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 '<a> <b>', 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()

78 changes: 78 additions & 0 deletions _sources/challenges/BasicExercises/Reto07.rst
Original file line number Diff line number Diff line change
@@ -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()
79 changes: 79 additions & 0 deletions _sources/challenges/BasicExercises/Reto07_en.rst
Original file line number Diff line number Diff line change
@@ -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()
Loading