diff --git a/exercises/08.2-Divide_and_conquer/README.es.md b/exercises/08.2-Divide_and_conquer/README.es.md index f8e3c6fc..563536be 100644 --- a/exercises/08.2-Divide_and_conquer/README.es.md +++ b/exercises/08.2-Divide_and_conquer/README.es.md @@ -2,25 +2,32 @@ ## 📝 Instrucciones: -1. Crea una función llamada `merge_two_list` que espere una lista números enteros. +1. Crea una función llamada `sort_odd_even` que espere una lista de números enteros. -2. Itera la lista y separa los números pares e impares en diferentes listas. +2. Itera la lista y separa los números *pares* e *impares*. -3. Si el número es impar colócalo en una lista llamada `odd`. +3. Crea una lista vacía llamada `sorted_list` y empieza a insertar los números *impares*. -4. Si el número es par colócalo en una lista llamada `even`. +4. Si el número es par, colócalo en una lista llamada `even`. -5. Luego concatena la lista `odd` y la lista `even` para combinarlas. Recuerda que la lista `odd` va primero y que debes añadirle la lista `even`. +5. Luego concatena la lista `even` en `sorted_list`. Recuerda que los números *impares* van primero y luego debes añadirle la lista `even` después. ## 💡 Pista: + Crea variables vacías cuando necesites almacenar información. -## Resultado esperado: ++ Lee sobre el método `extend()`: https://www.w3schools.com/python/ref_list_extend.asp + +## 💻 Resultado esperado: + +Debe quedar todo dentro de una sola lista, no debe haber listas anidadas. ```py -mergeTwoList([1,2,33,10,20,4]) +sort_odd_even([1, 2, 33, 10, 20, 4]) -[[1,33,2], [10,20,4]] +[1, 33, 2, 10, 20, 4] # <-- Si +[[1,33], [2,10,20,4]] # <-- No ``` + + diff --git a/exercises/08.2-Divide_and_conquer/README.md b/exercises/08.2-Divide_and_conquer/README.md index 6133bdfb..dad03b80 100644 --- a/exercises/08.2-Divide_and_conquer/README.md +++ b/exercises/08.2-Divide_and_conquer/README.md @@ -1,25 +1,30 @@ -# `08.2` Divide and conquer: +# `08.2` Divide and conquer -## 📝Instructions: +## 📝 Instructions: -1. Create a function called `merge_two_list` that expects an list of numbers (integers). +1. Create a function called `sort_odd_even` that expects a list of numbers (integers). -2. Loop through the list and separate the `odd` and the `even` numbers in different lists. +2. Loop through the list and separate the *odd* and the *even* numbers. -3. If the number is odd number push it to a placeholder list named `odd`. +3. Create a variable called `sorted_list` to start appending the *odd* numbers. -4. If the number is even number push it to a placeholder list named `even`. +4. If the number is even, push it to a placeholder list named `even`. -5. Then concatenate the `odd` list to the even list to combine them. Remember, the `odd` list comes first and you have to append the even `mergeTwoList`. +5. Then insert the `even` list into the `sorted_list`. Remember, the *odd* numbers come first, and you have to insert the `even` list after. -## 💡 Hint: +## 💡 Hints: + Create empty (placeholder) variables when you need to store data. -## Expected result: ++ Check out the `extend()` method: https://www.w3schools.com/python/ref_list_extend.asp + +## 💻 Expected result: + +Everything should be inside a single list; there should not be nested lists. ```py -mergeTwoList([1,2,33,10,20,4]) +sort_odd_even([1, 2, 33, 10, 20, 4]) -[[1,33,2], [10,20,4]] +[1, 33, 2, 10, 20, 4] # <-- Yes +[[1,33], [2,10,20,4]] # <-- No ``` diff --git a/exercises/08.2-Divide_and_conquer/app.py b/exercises/08.2-Divide_and_conquer/app.py index a584ec4a..106fd02b 100644 --- a/exercises/08.2-Divide_and_conquer/app.py +++ b/exercises/08.2-Divide_and_conquer/app.py @@ -1,8 +1,7 @@ -list_of_numbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68] +list_of_numbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68] +# Your code here -#Your code here: - -print(merge_two_list(list_of_numbers)) +print(sort_odd_even(list_of_numbers)) diff --git a/exercises/08.2-Divide_and_conquer/solution.hide.py b/exercises/08.2-Divide_and_conquer/solution.hide.py new file mode 100644 index 00000000..cd6e09e4 --- /dev/null +++ b/exercises/08.2-Divide_and_conquer/solution.hide.py @@ -0,0 +1,17 @@ +list_of_numbers = [4, 80, 85, 59, 37, 25, 5, 64, 66, 81, 20, 64, 41, 22, 76, 76, 55, 96, 2, 68] + +# Your code here +def sort_odd_even(numbers): + sorted_list = [] + even = [] + + for i in numbers: + if (i % 2 == 1): + sorted_list.append(i) + elif (i % 2 == 0): + even.append(i) + + sorted_list.extend(even) + return sorted_list + +print(sort_odd_even(list_of_numbers)) diff --git a/exercises/08.2-Divide_and_conquer/test.py b/exercises/08.2-Divide_and_conquer/test.py index 254ce639..9bb7c65d 100644 --- a/exercises/08.2-Divide_and_conquer/test.py +++ b/exercises/08.2-Divide_and_conquer/test.py @@ -1,11 +1,11 @@ import io, sys, os, pytest, re path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -@pytest.mark.it("Concatenate both lists. Remember the Odd list come first") +@pytest.mark.it("Concatenate both lists. Remember the odd list comes first") def test_odd_even(capsys, app): import app captured = capsys.readouterr() - assert "[[85, 59, 37, 25, 5, 81, 41, 55], [4, 80, 64, 66, 20, 64, 22, 76, 76, 96, 2, 68]]\n" in captured.out + assert "[85, 59, 37, 25, 5, 81, 41, 55, 4, 80, 64, 66, 20, 64, 22, 76, 76, 96, 2, 68]\n" in captured.out @pytest.mark.it("Use the for loop") def test_for_loop(): @@ -14,16 +14,16 @@ def test_for_loop(): regex = re.compile(r"for(\s)") assert bool(regex.search(content)) == True -@pytest.mark.it("Use if statement") +@pytest.mark.it("Use an if statement") def test_if(): with open(path, 'r') as content_file: content = content_file.read() regex = re.compile(r"if(\s)") assert bool(regex.search(content)) == True -@pytest.mark.it('1. You should create a function named merge_two_list') +@pytest.mark.it('You should create a function named sort_odd_even') def test_variable_exists(app): try: - app.merge_two_list + app.sort_odd_even except AttributeError: - raise AttributeError("The function 'merge_two_list' should exist on app.py") \ No newline at end of file + raise AttributeError("The function 'sort_odd_even' should exist on app.py") diff --git a/exercises/09-Max_integer_from_list/README.es.md b/exercises/09-Max_integer_from_list/README.es.md index 75434507..49b539fa 100644 --- a/exercises/09-Max_integer_from_list/README.es.md +++ b/exercises/09-Max_integer_from_list/README.es.md @@ -2,20 +2,19 @@ ## 📝 Instrucciones: -1. Crea una función llamada `maxInteger`. +1. Crea una función llamada `max_integer`. 2. Esta función debe tomar una lista como parámetro de entrada y devolver el número máximo encontrado en la lista. -3. Deberías usar un bucle 'for' para recorrer la lista. +3. Deberías usar un bucle `for` para recorrer la lista. 4. Utiliza la función `print()` para imprimir lo que devuelve la función al ser llamada. - - Por **ejemplo**: `print(myFunction(param))` + + Por ejemplo: `print(my_function(param))` +## 💡 Pistas: -## 💡 Pista: - -- Defina una variable auxiliar y establece su valor en 0. +- Defina una variable auxiliar y establece su valor como el primer elemento de la lista. - Compara la variable con todos los elementos de la lista. @@ -23,8 +22,8 @@ - Al final, tendrás el número más grande almacenado en la variable. -## Resultado esperado: +## 💻 Resultado esperado: - ```py -Tu resultado debería ser 5435. -``` \ No newline at end of file +```py +5435 +``` diff --git a/exercises/09-Max_integer_from_list/README.md b/exercises/09-Max_integer_from_list/README.md index 9a708b48..f100cd55 100644 --- a/exercises/09-Max_integer_from_list/README.md +++ b/exercises/09-Max_integer_from_list/README.md @@ -2,28 +2,28 @@ ## 📝 Instructions: -1. Create a function named `maxInteger` +1. Create a function named `max_integer` -2. This function should take a list as an input parameter and -return the maximum number found in the list. +2. This function should take a list as an input parameter and return the maximum number found in the list. -3. You should use a 'for' loop to iterate through the list. +3. You should use a `for` loop to iterate through the list. 4. Use the `print()` function to print what the function returns when it is called. - - For **example**: `print(myFunction(param))` + + + For example: `print(my_function(param))` -## 💡 Hint: +## 💡 Hints: -- Define an auxiliar variable and set the first value to `0`. +- Define an auxiliary variable and set the first value to the first element on the list. -- Then compare the variables with all the items in the list. +- Then compare the variable with all the items in the list. -- Replace the value every time the new element is bigger than the one stored in the auxiliar variable. +- Replace the value every time the new element is bigger than the one stored in the auxiliary variable. -- At the end you will have the biggest number stored in the variable. +- At the end, you will have the biggest number stored in the variable. -## Expected Result: +## 💻 Expected result: - ```py -Your result should be 5435. +```py +5435 ``` diff --git a/exercises/09-Max_integer_from_list/app.py b/exercises/09-Max_integer_from_list/app.py index 98630f38..c0a5a543 100644 --- a/exercises/09-Max_integer_from_list/app.py +++ b/exercises/09-Max_integer_from_list/app.py @@ -1,3 +1,3 @@ my_list = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34] -#Your code go from here: +# Your code here diff --git a/exercises/09-Max_integer_from_list/solution.hide.py b/exercises/09-Max_integer_from_list/solution.hide.py index 3a334f92..a605de60 100644 --- a/exercises/09-Max_integer_from_list/solution.hide.py +++ b/exercises/09-Max_integer_from_list/solution.hide.py @@ -1,11 +1,12 @@ my_list = [43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34] -#Your code go from here: -def maxInteger(arr): - maxInt=0 - for i in range(len(arr)): - if arr[i] > maxInt: - maxInt = arr[i] - return maxInt +# Your code here +def max_integer(list): + max_int = list[0] + + for i in range(len(list)): + if list[i] > max_int: + max_int = list[i] + return max_int -print(maxInteger(my_list)) \ No newline at end of file +print(max_integer(my_list)) diff --git a/exercises/09-Max_integer_from_list/test.py b/exercises/09-Max_integer_from_list/test.py index da04e6b2..a010e2c8 100644 --- a/exercises/09-Max_integer_from_list/test.py +++ b/exercises/09-Max_integer_from_list/test.py @@ -1,18 +1,18 @@ import io, sys, os, pytest, re path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -@pytest.mark.it('The function maxInteger must exist') +@pytest.mark.it('The function max_integer must exist') def test_function_existence(capsys, app): - assert app.maxInteger + assert app.max_integer -@pytest.mark.it("The function should return the maximun number from a list") +@pytest.mark.it("The function should return the maximum number from a list") def test_output(capsys, app): - result = app.maxInteger([43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34]) + result = app.max_integer([43,23,6,87,43,1,4,6,3,67,8,3445,3,7,5435,63,346,3,456,734,6,34]) assert result == 5435 @pytest.mark.it("The function should work with other lists") def test_output_2(capsys, app): - result = app.maxInteger([43,23,6,8733,43,1,4,6,3,67,8,99999,3,7,5435,63]) + result = app.max_integer([43,23,6,8733,43,1,4,6,3,67,8,99999,3,7,5435,63]) assert result == 99999 @pytest.mark.it("Use the for loop") @@ -22,9 +22,9 @@ def test_for_loop(): regex = re.compile(r"for(\s)*") assert bool(regex.search(content)) == True -@pytest.mark.it("Use if statement") +@pytest.mark.it("Use an if statement") def test_if(): with open(path, 'r') as content_file: content = content_file.read() regex = re.compile(r"if(\s)*") - assert bool(regex.search(content)) == True \ No newline at end of file + assert bool(regex.search(content)) == True