diff --git a/exercises/24-class-with-two-methods/README.es.md b/exercises/24-class-with-two-methods/README.es.md index fffb54ba..fe7c5c59 100644 --- a/exercises/24-class-with-two-methods/README.es.md +++ b/exercises/24-class-with-two-methods/README.es.md @@ -1,10 +1,13 @@ -# `24` Una clase con dos métodos +# `24` Class with two methods -Define una clase que tenga al menos dos métodos: -Define a class which has at least two methods: -getString: obtener un string desde la entrada de la consola. -printString: imprimir el string en mayúscula. -Por favor incluye una función simple de prueba para probar los métodos de la clase. +## 📝 Instrucciones: -Pistas: -Usa el método __init__ para construir algunos parámetros. \ No newline at end of file +1. Define una clase llamada `InputOutString` que tenga al menos dos métodos: ++ `get_string` para obtener un string de entrada desde la consola. ++ `print_string` para imprimir el string obtenido en mayúsculas. + +2. Prueba los métodos de tu clase. + +## 💡 Pista: + ++ Usa el método `__init__` para construir tus parámetros. diff --git a/exercises/24-class-with-two-methods/README.md b/exercises/24-class-with-two-methods/README.md index 3971f14f..99a82215 100644 --- a/exercises/24-class-with-two-methods/README.md +++ b/exercises/24-class-with-two-methods/README.md @@ -1,9 +1,13 @@ # `24` Class with two methods -Define a class which has at least two methods: -getString: to get a string from console input -printString: to print the string in upper case. -Also please include simple test function to test the class methods. +## 📝 Instructions: -Hints: -Use __init__ method to construct some parameters \ No newline at end of file +1. Define a class called `InputOutString` which has at least two methods: ++ `get_string` to get a string from console input. ++ `print_string` to print the string in upper case. + +2. Test your class' methods. + +## 💡 Hint: + ++ Use the `__init__` method to construct your parameters. diff --git a/exercises/24-class-with-two-methods/app.py b/exercises/24-class-with-two-methods/app.py index e69de29b..a51f0856 100644 --- a/exercises/24-class-with-two-methods/app.py +++ b/exercises/24-class-with-two-methods/app.py @@ -0,0 +1 @@ +# Your code here diff --git a/exercises/24-class-with-two-methods/solution.hide.py b/exercises/24-class-with-two-methods/solution.hide.py index b6917e80..e53abdf1 100644 --- a/exercises/24-class-with-two-methods/solution.hide.py +++ b/exercises/24-class-with-two-methods/solution.hide.py @@ -1,13 +1,14 @@ -class InputOutString(object): +# Your code here +class InputOutString: def __init__(self): - self.s = "" + self.input_string = "" - def getString(self): - self.s = raw_input() + def get_string(self): + self.input_string = input("Enter a string: ") - def printString(self): - print self.s.upper() + def print_string(self): + print(self.input_string.upper()) -strObj = InputOutString() -strObj.getString() -strObj.printString() \ No newline at end of file +string_object = InputOutString() +string_object.get_string() +string_object.print_string() diff --git a/exercises/25-print-formula/README.es.md b/exercises/25-print-formula/README.es.md index e38c0d3b..4a6d7736 100644 --- a/exercises/25-print-formula/README.es.md +++ b/exercises/25-print-formula/README.es.md @@ -1,19 +1,33 @@ -# `25` Imprime la fórmula +# `25` Print formula -Escribe un programa que calcule e imprima el valor de acuerdo a la fórmula dada: +## 📝 Instrucciones: -Q = Square root of [(2 * C * D)/H] +1. Escribe una función llamada `print_formula()`, con un parámetro que calcule e imprima el valor según la fórmula dada. -A continuación encontrarás los valores fijos de C y H: -C es 50. H es 30. -D es la variable cuyos valores debiesen ser ingresados en tu -Ejemplo: -Digamos que le sentrega la siguiente secuencia separada por coma al programa: -100,150,180 -El resultado del programa debiese ser: -18,22,24 +```text +Q = Square root of (2 * c * d) / h +``` -Pistas: -Si el resultado recicido es un decimal, debería rendondearse a su valor más cercano (por ejemplo, si el resultado es 26.0, debiese imprimirse como 26) -En el caso de que se le hayan entregado datos a la cuestión, deben asumirse como una entrada de la consola. - \ No newline at end of file +*A continuación encontrarás los valores fijos de `c` y `h`:* + ++ `c` es 50. ++ `h` es 30. ++ `d` sería el parámetro de la función. + +## 📎 Ejemplo de entrada: + +```py +print_formula(150) +``` + +## 📎 Ejemplo de salida: + +```py +22 +``` + +## 💡 Pistas: + ++ Si el resultado recibido es un decimal, debería redondearse a su valor más cercano (por ejemplo, si el resultado es 26.0, debiese imprimirse como 26). + ++ Importa el módulo `math`. diff --git a/exercises/25-print-formula/README.md b/exercises/25-print-formula/README.md index b47224b0..0abc0f7a 100644 --- a/exercises/25-print-formula/README.md +++ b/exercises/25-print-formula/README.md @@ -1,17 +1,33 @@ # `25` Print formula -Write a program that calculates and prints the value according to the given formula: -Q = Square root of [(2 * C * D)/H] - -Following are the fixed values of C and H: -C is 50. H is 30. -D is the variable whose values should be input to your program in a comma-separated sequence. -Example -Let us assume the following comma separated input sequence is given to the program: -100,150,180 -The output of the program should be: -18,22,24 - -Hints: -If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26) -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +## 📝 Instructions: + +1. Write a function `print_formula()`, with one parameter that calculates and prints the value according to the given formula: + +```text +Q = Square root of (2 * c * d) / h +``` + +*Following are the fixed values of `c` and `h`:* + ++ `c` is 50. ++ `h` is 30. ++ `d` would be the parameter of the function. + +## 📎 Example input: + +```py +print_formula(150) +``` + +## 📎 Example output: + +```py +22 +``` + +## 💡 Hints: + ++ If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26). + ++ Import the `math` module. diff --git a/exercises/25-print-formula/app.py b/exercises/25-print-formula/app.py index e69de29b..a51f0856 100644 --- a/exercises/25-print-formula/app.py +++ b/exercises/25-print-formula/app.py @@ -0,0 +1 @@ +# Your code here diff --git a/exercises/25-print-formula/solution.hide.py b/exercises/25-print-formula/solution.hide.py index 10c47e5b..3ddcff9c 100644 --- a/exercises/25-print-formula/solution.hide.py +++ b/exercises/25-print-formula/solution.hide.py @@ -1,5 +1,7 @@ +# Your code here import math -def print_formula(num): - return round(math.sqrt(2*50*num/30)) -print(print_formula(5)) \ No newline at end of file +def print_formula(d): + return round(math.sqrt(2 * 50 * d / 30)) + +print(print_formula(150)) diff --git a/exercises/25-print-formula/test.py b/exercises/25-print-formula/test.py index 27181781..0bb388ba 100644 --- a/exercises/25-print-formula/test.py +++ b/exercises/25-print-formula/test.py @@ -5,11 +5,11 @@ def test_function_existence(capsys, app): assert app.print_formula -@pytest.mark.it('The solution should work as expected') +@pytest.mark.it('The solution should work as expected. Testing with 100') def test_expected_output(capsys, app): - assert app.print_formula(100,150,180) == "18,22,24" + assert app.print_formula(100) == 18 -@pytest.mark.it('The solution should work as expected') +@pytest.mark.it('The solution should work as expected. Testing with 90') def test_another_output(capsys, app): - assert app.print_formula(200,90,300) == "26,17,32" + assert app.print_formula(90) == 17 diff --git a/exercises/26-two-dimensional-array/README.es.md b/exercises/26-two-dimensional-array/README.es.md index b81dd4a6..c6a0a771 100644 --- a/exercises/26-two-dimensional-array/README.es.md +++ b/exercises/26-two-dimensional-array/README.es.md @@ -1,13 +1,19 @@ -# `26` Array de dos dimensiones +# `26` Two dimensional list -Escribe un progrsms que reciba dos dígitos X,Y como entrada y genere un array de dos dimensiones. El valor del elemento en la fila i-th y en la columna j-th del array debiese ser i*j. -Nota: i=0,1.., X-1; j=0,1,¡­Y-1. -Ejemplo: -Supongamos que se le entregan lasa siguientes entradas al programa: -3,5 -Entonces, el resultado del programa debería ser: -[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] +## 📝 Instrucciones: -Pistas: -Nota: En el caso de que se le entreguen datos a la cuestión, debe asumirse como una entrada de la consola en un formulario separado por comas. +1. Escribe una función llamada `two_dimensional_list()` que tome 2 dígitos (x, y) como entrada y genere una lista bidimensional o matriz. +2. El valor del elemento en la fila `i` y columna `j` de la lista debería ser `i*j` (los valores de sus índices). + +## 📎 Ejemplo de entrada: + +```py +two_dimensional_list(3,5) +``` + +## 📎 Ejemplo de salida: + +```py +[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] +``` diff --git a/exercises/26-two-dimensional-array/README.md b/exercises/26-two-dimensional-array/README.md index 330f75a5..eed36f28 100644 --- a/exercises/26-two-dimensional-array/README.md +++ b/exercises/26-two-dimensional-array/README.md @@ -1,12 +1,20 @@ -# `26`Two dimensional array - -Write a program which takes 2 digits, X,Y as input and generates a 2-dimensional array. The element value in the i-th row and j-th column of the array should be i*j. -Note: i=0,1.., X-1; j=0,1,¡­Y-1. -Example -Suppose the following inputs are given to the program: -3,5 -Then, the output of the program should be: -[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] - -Hints: -Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form. \ No newline at end of file +# `26` Two dimensional list + +## 📝 Instructions: + +1. Write a function `two_dimensional_list()`, that takes 2 digits (x, y) as input and generates a 2-dimensional list or matrix. + +2. The element value in the `i` row and `j` column of the list should be `i*j` (their index values). + +## 📎 Example input: + +```py +two_dimensional_list(3,5) +``` + +## 📎 Example output: + +```py +[[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] +``` + diff --git a/exercises/26-two-dimensional-array/app.py b/exercises/26-two-dimensional-array/app.py index e69de29b..a51f0856 100644 --- a/exercises/26-two-dimensional-array/app.py +++ b/exercises/26-two-dimensional-array/app.py @@ -0,0 +1 @@ +# Your code here diff --git a/exercises/26-two-dimensional-array/solution.hide.py b/exercises/26-two-dimensional-array/solution.hide.py index c1279fd2..190ac67e 100644 --- a/exercises/26-two-dimensional-array/solution.hide.py +++ b/exercises/26-two-dimensional-array/solution.hide.py @@ -1,11 +1,14 @@ -def two_dimensional_array(nList, nElements): - dimensions=[int(x) for x in "{},{}".format(nList,nElements).split(',')] - rowNum=dimensions[0] - colNum=dimensions[1] - multilist = [[0 for col in range(colNum)] for row in range(rowNum)] +# Your code here +def two_dimensional_list(n_rows, n_columns): + dimensions = [int(x) for x in "{},{}".format(n_rows, n_columns).split(',')] + row_num = dimensions[0] + col_num = dimensions[1] + matrix = [[0 for col in range(col_num)] for row in range(row_num)] - for row in range(rowNum): - for col in range(colNum): - multilist[row][col]= row*col + for row in range(row_num): + for col in range(col_num): + matrix[row][col] = row * col - return (multilist) + return matrix + +print(two_dimensional_list(3,5)) diff --git a/exercises/26-two-dimensional-array/test.py b/exercises/26-two-dimensional-array/test.py index 5cd0300c..833f3836 100644 --- a/exercises/26-two-dimensional-array/test.py +++ b/exercises/26-two-dimensional-array/test.py @@ -1,18 +1,17 @@ - import pytest,os,re,io,sys, mock, json -@pytest.mark.it('The function two_dimensional_array must exist') +@pytest.mark.it('The function two_dimensional_list must exist') def test_function_existence(capsys, app): - assert app.two_dimensional_array + assert app.two_dimensional_list -@pytest.mark.it('The function should return the expected output.') +@pytest.mark.it('The function should return the expected output') def test_expected_output(capsys, app): - assert app.two_dimensional_array(3,5) == [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] + assert app.two_dimensional_list(3,5) == [[0, 0, 0, 0, 0], [0, 1, 2, 3, 4], [0, 2, 4, 6, 8]] -@pytest.mark.it('The function should work with other entries. Testing with 2,7') +@pytest.mark.it('The function should work with other entries. Testing with (2, 7)') def test_expected_output(capsys, app): - assert app.two_dimensional_array(2,7) == [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6]] + assert app.two_dimensional_list(2,7) == [[0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 4, 5, 6]] -@pytest.mark.it('The function should work with other entries. Testing with 2,7') +@pytest.mark.it('The function should work with other entries. Testing with (1, 10)') def test_expected_output(capsys, app): - assert app.two_dimensional_array(1,10) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] + assert app.two_dimensional_list(1,10) == [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] diff --git a/exercises/27-sequence-of-words/README.es.md b/exercises/27-sequence-of-words/README.es.md index 290fdecf..05255296 100644 --- a/exercises/27-sequence-of-words/README.es.md +++ b/exercises/27-sequence-of-words/README.es.md @@ -1,10 +1,23 @@ -# `27` Secuencia de palabras +# `27` Sequence of words -Escribe un programa que acepte una secuencia separada por comas como entrada e imprima las palabras en una secuencia separada por comas después de ordenarlas alfabéticamente. -Supongamos que se le entrega la siguiente entrada al programa: -without,hello,bag,world -El resultado debiese ser: -bag,hello,without,world +## 📝 Instrucciones: -Pistas: -En el caso de que se le entreguen datos a la pregunta, deben considerarse como entradas de la consola. +1. Escribe una función llamada `sequence_of_words()`, que acepte una secuencia de palabras separadas por comas como entrada (un string). + +2. Imprime las palabras en una secuencia separada por comas después de ordenarlas alfabéticamente. + +## 📎 Ejemplo de entrada: + +```py +sequence_of_words("without,hello,bag,world") +``` + +## 📎 Ejemplo de salida: + +```py +bag, hello, without, world +``` + +## 💡 Pista: + ++ Recuerda que cada palabra debe estar separada por una coma y dentro de UN SOLO par de comillas. diff --git a/exercises/27-sequence-of-words/README.md b/exercises/27-sequence-of-words/README.md index be2f8cf0..3cacba0b 100644 --- a/exercises/27-sequence-of-words/README.md +++ b/exercises/27-sequence-of-words/README.md @@ -1,10 +1,23 @@ -# `27`Sequence of words +# `27` Sequence of words -Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically. -Suppose the following input is supplied to the program: -without,hello,bag,world -Then, the output should be: -bag,hello,without,world +## 📝 Instructions: -Hints: -In case of input data being supplied to the question, it should be assumed to be a console input. \ No newline at end of file +1. Write a function `sequence_of_words`, that accepts a comma separated sequence of words as input (a string). + +2. Print the words in a comma-separated sequence after sorting them alphabetically. + +## 📎 Example input: + +```py +sequence_of_words("without,hello,bag,world") +``` + +## 📎 Example output: + +```py +bag, hello, without, world +``` + +## 💡 Hint: + ++ Remember that each word must be separated by a comma and inside ONLY ONE pair of quotes. diff --git a/exercises/27-sequence-of-words/app.py b/exercises/27-sequence-of-words/app.py index e69de29b..a51f0856 100644 --- a/exercises/27-sequence-of-words/app.py +++ b/exercises/27-sequence-of-words/app.py @@ -0,0 +1 @@ +# Your code here diff --git a/exercises/27-sequence-of-words/solution.hide.py b/exercises/27-sequence-of-words/solution.hide.py index 75bddc17..71949469 100644 --- a/exercises/27-sequence-of-words/solution.hide.py +++ b/exercises/27-sequence-of-words/solution.hide.py @@ -1,4 +1,7 @@ +# Your code here def sequence_of_words(words): items=[x for x in "{}".format(words).split(',')] items.sort() return (','.join(items)) + +print(sequence_of_words("this,is,sorted")) diff --git a/exercises/27-sequence-of-words/test.py b/exercises/27-sequence-of-words/test.py index b48ffb1d..0b82f45e 100644 --- a/exercises/27-sequence-of-words/test.py +++ b/exercises/27-sequence-of-words/test.py @@ -9,6 +9,6 @@ def test_function_existence(capsys, app): def test_function_existence(capsys, app): assert app.sequence_of_words("bag,hello,without,world") == "bag,hello,without,world" -@pytest.mark.it('The function should return the expected output') +@pytest.mark.it('The function should return the expected output. Testing with different values') def test_function_existence(capsys, app): - assert app.sequence_of_words("No,pain,gain") == "No,gain,pain" \ No newline at end of file + assert app.sequence_of_words("No,pain,gain") == "No,gain,pain"