diff --git a/exercises/09.1-For_loop_min_value/README.es.md b/exercises/09.1-For_loop_min_value/README.es.md index d872e6f1..e37a2a26 100644 --- a/exercises/09.1-For_loop_min_value/README.es.md +++ b/exercises/09.1-For_loop_min_value/README.es.md @@ -1,22 +1,22 @@ -# `09.1` Minimum integer +# `09.1` Minimum Integer -Es posible recorrer una lista usando un bucle `for` para listas, tú tienes que especificar qué hacer en cada iteración de la lista. +Es posible recorrer una lista usando un bucle `for`, y luego especificar qué hacer en cada iteración de la lista. ## 📝 Instrucciones: -1. Por favor, usa la función for para obtener el menor valor de la lista e imprimirlo en la consola. +1. Por favor, usa la función `for` para obtener el menor valor de la lista e imprimirlo en la consola. -## 💡 Pista: +## 💡 Pistas: -* Declara una variable auxiliar global. ++ Declara una variable auxiliar global. -* Establece su valor inicial con un entero muy grande. ++ Establece su valor inicial con el primer elemento de la lista. -* Cada vez que iteres, compara su valor con el valor del elemento, si el valor del elemento es más pequeño, asígnalo como nuevo valor de la variable auxiliar. ++ Cada vez que iteres, compara su valor con el valor del siguiente elemento, si el valor del elemento es más pequeño, asígnalo como nuevo valor en la variable auxiliar. -* Fuera del bucle, después de que el bucle haya finalizado, imprime el valor auxiliar. ++ Fuera del bucle, después de que el bucle haya finalizado, imprime el valor auxiliar. -## Resultado esperado: +## 💻 Resultado esperado: ```py 23 diff --git a/exercises/09.1-For_loop_min_value/README.md b/exercises/09.1-For_loop_min_value/README.md index 6082ddcd..e06e0afd 100644 --- a/exercises/09.1-For_loop_min_value/README.md +++ b/exercises/09.1-For_loop_min_value/README.md @@ -1,23 +1,22 @@ -# `09.1` Minimum integer: +# `09.1` Minimum Integer -It is possible to traverse a list using the `for` loop, you have to specify what to do on each iteration of the loop. +It is possible to traverse a list using the `for` loop, and you have to specify what to do on each iteration of the loop. +## 📝 Instructions: -## 📝Instructions: +1. Please use the `for` loop function to get the minimum value from the list and print it in the console. -1. Please use the `for` loop function to get the minimum value of the list and print it in the console. +## 💡 Hints: -## 💡 Hint: ++ Declare an auxiliary global variable. -* Declare an Auxiliary Global Variable. ++ Set its value to the first element on the list. -* Set it's value to a very big interger. ++ Every time you loop, compare its value to the next element's value, if it's smaller, update the auxiliary variable's value to the element's value. -* Every time you loop, compare it's value to the item value. If the item value is smaller, update the auxiliary variable value to the item value. ++ Outside the loop, after the loop is finished, print the auxiliary variable's value. -* Outside of the loop, after the loop is finished, print the auxiliary value. - -## Expected result: +## 💻 Expected result: ```py 23 diff --git a/exercises/09.1-For_loop_min_value/app.py b/exercises/09.1-For_loop_min_value/app.py index a6f8c057..594b1d3d 100644 --- a/exercises/09.1-For_loop_min_value/app.py +++ b/exercises/09.1-For_loop_min_value/app.py @@ -1,7 +1,3 @@ -my_list = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335, -43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63, -425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523, -566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644, -35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343] +my_list = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343] -#Your code here: +# Your code here diff --git a/exercises/09.1-For_loop_min_value/solution.hide.py b/exercises/09.1-For_loop_min_value/solution.hide.py index e752cc58..e7299394 100644 --- a/exercises/09.1-For_loop_min_value/solution.hide.py +++ b/exercises/09.1-For_loop_min_value/solution.hide.py @@ -1,8 +1,11 @@ -big_number = 999999999999999 +my_list = [3344,34334,454543,342534,4563456,3445,23455,234,262,2335,43323,4356,345,4545,452,345,434,36,345,4334,5454,345,4352,23,365,345,47,63,425,6578759,768,834,754,35,32,445,453456,56,7536867,3884526,4234,35353245,53244523,566785,7547,743,4324,523472634,26665,63432,54645,32,453625,7568,5669576,754,64356,542644,35,243,371,3251,351223,13231243,734,856,56,53,234342,56,545343] + +# Your code here + +smallest_integer = my_list[0] for number in my_list: - if number < big_number: - big_number = number + if number < smallest_integer: + smallest_integer = number - -print(big_number) \ No newline at end of file +print(smallest_integer) diff --git a/exercises/09.1-For_loop_min_value/test.py b/exercises/09.1-For_loop_min_value/test.py index 18a2cce4..eac697c9 100644 --- a/exercises/09.1-For_loop_min_value/test.py +++ b/exercises/09.1-For_loop_min_value/test.py @@ -14,9 +14,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 diff --git a/exercises/10-Find_avg/README.es.md b/exercises/10-Find_avg/README.es.md index be4b5878..fd770362 100644 --- a/exercises/10-Find_avg/README.es.md +++ b/exercises/10-Find_avg/README.es.md @@ -1,20 +1,19 @@ -# `10` Find the average +# `10` Find average ## 📝 Instrucciones: -1. Declara una variable con valor `0`. +1. Calcula el valor promedio de todos los elementos de la lista e imprímelo en la consola. -2. Calcula el valor promedio de todos los elementos de la lista e imprímelo en la consola. +## 💡 Pistas: -## Resultado esperado: ++ Para imprimir el promedio, tienes que sumar todos los valores y dividir el total entre la cantidad de elementos de la lista. -```py -El resultado debería ser similar a: -27278.8125 -``` ++ Debes usar un bucle `for`. -## 💡 Pistas: ++ Puedes usar tantas variables auxiliares como necesites. -+ Para imprimir el promedio, tienes que sumar todos los valores y dividir el total entre la cantidad de elementos de la lista. +## 💻 Resultado esperado: -+ Debes usar un ciclo for. \ No newline at end of file +```py +27278.8125 +``` diff --git a/exercises/10-Find_avg/README.md b/exercises/10-Find_avg/README.md index 79119820..97bbf155 100644 --- a/exercises/10-Find_avg/README.md +++ b/exercises/10-Find_avg/README.md @@ -1,20 +1,19 @@ # `10` Find average -## 📝Instructions: +## 📝 Instructions: -1. Declare a variable with value `0`. +1. Calculate the average value of all the items in the list and print it on the console. -2. Calculate the average value of all the items in the list and print it on the console. +## 💡 Hints: -## Expected result: ++ To print the average, you have to add all the values and divide the result by the total length of the list. -```py -The result have to be like: -27278.8125 -``` ++ Make sure you are using a `for` loop. -## 💡 Hints: ++ You can use as many auxiliary variables as you need. -+ To print the average, you have to add all the values and divide the result by the total length of the list. +## 💻 Expected result: -+ Make sure you are using a for loop. \ No newline at end of file +```py +27278.8125 +``` diff --git a/exercises/10-Find_avg/app.py b/exercises/10-Find_avg/app.py index 823c467d..c881b318 100644 --- a/exercises/10-Find_avg/app.py +++ b/exercises/10-Find_avg/app.py @@ -1,3 +1,3 @@ my_list = [2323,4344,2325,324413,21234,24531,2123,42234,544,456,345,42,5445,23,5656,423] -#Your code here: +# Your code here diff --git a/exercises/10-Find_avg/solution.hide.py b/exercises/10-Find_avg/solution.hide.py new file mode 100644 index 00000000..aa38a2a8 --- /dev/null +++ b/exercises/10-Find_avg/solution.hide.py @@ -0,0 +1,11 @@ +my_list = [2323,4344,2325,324413,21234,24531,2123,42234,544,456,345,42,5445,23,5656,423] + +# Your code here +total = 0 + +for num in my_list: + total += num + +average = total / len(my_list) + +print(average) diff --git a/exercises/10.1-And_One_and_a_Two_and_a_Three/README.es.md b/exercises/10.1-And_One_and_a_Two_and_a_Three/README.es.md index 09bbb68a..e6f559a3 100644 --- a/exercises/10.1-And_One_and_a_Two_and_a_Three/README.es.md +++ b/exercises/10.1-And_One_and_a_Two_and_a_Three/README.es.md @@ -1,27 +1,25 @@ # `10.1` And one and two and three -Los diccionarios (o `dict` en Python) son una forma de almacenar elementos como lo harías en una lista de Python, con la diferencia de que en lugar de acceder a los elementos por su índice, asignas una clave fija a cada uno y accedes al elemento usando su clave. A lo que te enfrentas ahora es un par `key-value` ("clave-valor"), el cual es, en ocasiones, una estructura de datos más apropiada para muchos problemas, en lugar de una simple lista. +Los diccionarios (o "dict" en Python) son una forma de almacenar elementos como lo harías en una lista de Python, con la diferencia de que en lugar de acceder a los elementos por su índice, asignas una clave fija a cada uno y accedes al elemento usando su clave. A lo que te enfrentas ahora es a un par `key-value` (clave-valor), el cual es, en ocasiones, una estructura de datos más apropiada para diferentes problemas, en lugar de una simple lista. ## 📝 Instrucciones: -1. Dado un objeto `contact`, por favor **itera todas sus propiedades y valores** e imprímelos en la consola. +1. Dado un objeto `contact`, por favor itera todas sus claves y valores e imprímelos en la consola. 2. Tendrás que iterar sus propiedades para poder imprimirlos -## 💡 Pista: +## 💡 Pistas: - contact.keys() `['fullname', 'phone', 'email']`. - contact.values() `['Jane Doe', '321-321-4321', 'test@test.com']`. -- contact.items() `[('fullname', 'Jane Doe'), ('phone', '321-321-4321'), ``('email', 'test@test.com')]` +- contact.items() `[('fullname', 'Jane Doe'), ('phone', '321-321-4321'), ('email', 'test@test.com')]` -## Resultado esperado: +## 💻 Ejemplo de resultado: ```py -Ejemplo de salida: - -fullname : John Doe -phone : 123-123-2134 -email : test@nowhere.com +fullname: John Doe +phone: 123-123-2134 +email: test@nowhere.com ``` diff --git a/exercises/10.1-And_One_and_a_Two_and_a_Three/README.md b/exercises/10.1-And_One_and_a_Two_and_a_Three/README.md index 6a71fa96..1f394435 100644 --- a/exercises/10.1-And_One_and_a_Two_and_a_Three/README.md +++ b/exercises/10.1-And_One_and_a_Two_and_a_Three/README.md @@ -1,25 +1,25 @@ # `10.1` And one and two and three -Dictionaries (or dict in Python) are a way of storing elements just like you would in a Python list but intead of accessing elements using its index, you assign a fixed key to it and access the element using the key. What you now deal with is a `key-value` pair, which is sometimes a more appropriate data structure or many problems instead of a simple list. +Dictionaries (or "dict" in Python) are a way of storing elements just like you would in a Python list, but instead of accessing elements using its index, you assign a fixed key to it and access the element using the key. What you now deal with is a `key-value` pair, which is sometimes a more appropriate data structure for solving different problems than a simple list. -## 📝Instructions: +## 📝 Instructions: -1. Given a contact object, please `loop all its properties and values` and print them on the console. +1. Given a contact dictionary, please loop through all its keys and values and print them on the console. -2. You will have to loop its properties to be able to print them. +2. You will have to loop over its keys to be able to print them. -## 💡Hint: +## 💡 Hints: - contact.keys() `['fullname', 'phone', 'email']` - contact.values() `['Jane Doe', '321-321-4321', 'test@test.com']` -- contact.items() `[('fullname', 'Jane Doe'), ('phone', '321-321-4321'), ``('email', 'test@test.com')]` +- contact.items() `[('fullname', 'Jane Doe'), ('phone', '321-321-4321'), ('email', 'test@test.com')]` -## Example console output: +## 💻 Example console output: ```py -fullname : John Doe -phone : 123-123-2134 -email : test@nowhere.com -``` \ No newline at end of file +fullname: John Doe +phone: 123-123-2134 +email: test@nowhere.com +``` diff --git a/exercises/10.1-And_One_and_a_Two_and_a_Three/app.py b/exercises/10.1-And_One_and_a_Two_and_a_Three/app.py index 8ba5d016..54e60221 100644 --- a/exercises/10.1-And_One_and_a_Two_and_a_Three/app.py +++ b/exercises/10.1-And_One_and_a_Two_and_a_Three/app.py @@ -3,5 +3,6 @@ "phone": "321-321-4321", "email": "test@test.com" } -#Your code here: + +# Your code here diff --git a/exercises/10.1-And_One_and_a_Two_and_a_Three/solution.hide.py b/exercises/10.1-And_One_and_a_Two_and_a_Three/solution.hide.py new file mode 100644 index 00000000..b5e67bec --- /dev/null +++ b/exercises/10.1-And_One_and_a_Two_and_a_Three/solution.hide.py @@ -0,0 +1,10 @@ +contact = { + "fullname": "Jane Doe", + "phone": "321-321-4321", + "email": "test@test.com" +} + +# Your code here + +for key in contact.keys(): + print(f"{key}: {contact[key]}") diff --git a/exercises/11-Nested_list/README.es.md b/exercises/11-Nested_list/README.es.md index cd7f6736..b732de51 100644 --- a/exercises/11-Nested_list/README.es.md +++ b/exercises/11-Nested_list/README.es.md @@ -1,28 +1,27 @@ # `11` Nested list - Es posible encontrar una lista dentro de otra lista (se llama lista de dos dimensiones o matriz). En este ejemplo, tenemos una lista de coordenadas a las que puedes acceder haciendo lo siguiente: ```py -longitude = [] -# bucle for en longitud -longitude = coordinatesList[0][1]; +# La primera coordenada es latitud +latitude = coordinates_list[0][0] +# La segunda coordenada es longitud +longitude = coordinates_list[0][1] ``` ## 📝 Instrucciones: -1. Itera la lista imprimiendo solo las longitudes. +1. Itera la lista imprimiendo solo las *longitudes*. ## 💡 Pista: -* Recuerda que el índice en la primera posición es list[0]. ++ Recuerda que el índice en la primera posición es `list[0]`. -## Resultado esperado: +## 💻 Resultado esperado: ```py -El resultado debería ser algo como esto: -112.633853 -63.987 -81.901693 diff --git a/exercises/11-Nested_list/README.md b/exercises/11-Nested_list/README.md index 97c80074..6701639d 100644 --- a/exercises/11-Nested_list/README.md +++ b/exercises/11-Nested_list/README.md @@ -1,29 +1,27 @@ # `11` Nested list -It is possible to find a list comprised of other lists (it is called a two-dimension list or matrix). +It is possible to find a list comprised of other lists (it is called a two-dimensional list or matrix). In this example, we have a list of coordinates that you can access by doing the following: ```py -longitude = [] - -for loop in coordinate longitude - -longitude = coordinatesList[0][1]; +# The first coordinate is latitude +latitude = coordinates_list[0][0] +# The second coordinate is longitude +longitude = coordinates_list[0][1] ``` -## 📝Instructions: +## 📝 Instructions: -1. Loop through the list printing only the longitudes. +1. Loop through the list, printing only the *longitudes*. ## 💡 Hint: -- Remember the index of the position 1 is list[0] ++ Remember, the index of the first item in a list is `list[0]`. -## Expected result: +## 💻 Expected result: ```py -The result should be something like this: -112.633853 -63.987 -81.901693 diff --git a/exercises/11-Nested_list/app.py b/exercises/11-Nested_list/app.py index 467f6ad8..c08ecc4a 100644 --- a/exercises/11-Nested_list/app.py +++ b/exercises/11-Nested_list/app.py @@ -1,6 +1,3 @@ +coordinates_list = [[33.747252, -112.633853], [-33.867886, -63.987], [41.303921, -81.901693], [-33.350534, -71.653268]] -coordinatesList = [[33.747252,-112.633853],[-33.867886, -63.987],[41.303921, -81.901693],[-33.350534, -71.653268]] - -# Your code go here: - - +# Your code here diff --git a/exercises/11-Nested_list/solution.hide.py b/exercises/11-Nested_list/solution.hide.py new file mode 100644 index 00000000..f92c9fcf --- /dev/null +++ b/exercises/11-Nested_list/solution.hide.py @@ -0,0 +1,6 @@ +coordinates_list = [[33.747252, -112.633853], [-33.867886, -63.987], [41.303921, -81.901693], [-33.350534, -71.653268]] + +# Your code here + +for coord in coordinates_list: + print(coord[1]) diff --git a/exercises/12-Map_a_list/README.es.md b/exercises/12-Map_a_list/README.es.md index 9b011fab..7dbeb820 100644 --- a/exercises/12-Map_a_list/README.es.md +++ b/exercises/12-Map_a_list/README.es.md @@ -1,15 +1,11 @@ # `12` Map a list -```py -Python map() -``` - -La función `map()` aplica una función dada a cada elemento de un 'iterable' (ya sea lista, tupla, etc.) y devuelve una lista de resultados. +La función `map()` aplica una función dada a cada elemento de un "iterable" (ya sea lista, tupla, etc.) y devuelve una lista de resultados. ### La sintaxis de map() es: ```py -map(funcion, iterable, ...) +map(función, iterable, ...) ``` #### Parámetros de map(): @@ -22,15 +18,22 @@ map(funcion, iterable, ...) La función `map()` aplica una función dada a cada elemento de un iterable y devuelve una lista de resultados. -El valor devuelto por `map()`, que es un map object, es pasado a funciones como `list()` (para crear una lista), `set()` (para crear un conjunto) y así. +El valor devuelto por `map()`, que es un *map object*, es pasado a funciones como `list()` (para crear una lista), `set()` (para crear un conjunto) y así. ## 📝 Instrucciones: 1. Usando la misma lógica, agrega el código necesario para convertir una lista de valores Celsius en Fahrenheit dentro de la función `map()`. -## Resultado esperado: +## 💻 Resultado esperado: ```py -Salida esperada en la consola: [28.4, 93.2, 132.8, 14.0] ``` + +## 💡 Pista: + ++ Para convertir de Celsius a Fahrenheit, multiplica la temperatura en Celsius por 9/5 y luego sumale 32. + +```text +(Cº * 9/5) + 32 +``` diff --git a/exercises/12-Map_a_list/README.md b/exercises/12-Map_a_list/README.md index 2ce9f3a3..9a9b25ce 100644 --- a/exercises/12-Map_a_list/README.md +++ b/exercises/12-Map_a_list/README.md @@ -1,17 +1,14 @@ # `12` Map a list -```py -Python map() -``` - -The `map()` function applies a given function to each item of an iterable (list, tuple etc.) and returns a list of the results. +The `map()` function applies a given function to each item of an "iterable" (list, tuple, etc.) and returns a list of the results. ### The syntax of map() is: ```py map(function, iterable, ...) ``` -#### map() Parameter: + +#### map() Parameters: **function:** passes each item of the iterable to this function. @@ -19,19 +16,24 @@ map(function, iterable, ...) #### Return Value from map(): -The `map()` function applies to a given function and in particular to each item of an iterable and returns a list of the results. +The `map()` function applies to a given function and, in particular, to each item of an iterable to return a list of the results. -The returned value from `map()` (map object) then can be passed to functions -like list() (to create a list), set() (to create a set) and so on. +The returned value from `map()` (map object) then can be passed to functions like `list()` (to create a list), `set()` (to create a set) and so on. -## 📝Instructions: +## 📝 Instructions: 1. Using the same logic, add the needed code to convert a list of Celsius values into Fahrenheit inside the `map()` function. -## Expected result: +## 💻 Expected result: ```py -Expected in console: - [28.4, 93.2, 132.8, 14.0] ``` + +## 💡 Hint: + ++ To convert from Celsius to Fahrenheit, multiply the Celsius temperature by 9/5 and add 32. + +```text +(Cº * 9/5) + 32 +``` diff --git a/exercises/12-Map_a_list/app.py b/exercises/12-Map_a_list/app.py index f0b071cc..bbaa6e5d 100644 --- a/exercises/12-Map_a_list/app.py +++ b/exercises/12-Map_a_list/app.py @@ -1,9 +1,9 @@ -Celsius_values = [-2,34,56,-10] +celsius_values = [-2, 34, 56, -10] +def celsius_to_fahrenheit(celsius): + # The magic happens here + +result = list(map(celsius_to_fahrenheit, celsius_values)) -def fahrenheit_values(x): -# the magic go here: - -result = list(map(fahrenheit_values, Celsius_values)) print(result) diff --git a/exercises/12-Map_a_list/solution.hide.py b/exercises/12-Map_a_list/solution.hide.py new file mode 100644 index 00000000..5b8c8b04 --- /dev/null +++ b/exercises/12-Map_a_list/solution.hide.py @@ -0,0 +1,9 @@ +celsius_values = [-2, 34, 56, -10] + +def celsius_to_fahrenheit(celsius): + # The magic happens here + return (celsius * 9/5) + 32 + +result = list(map(celsius_to_fahrenheit, celsius_values)) + +print(result) diff --git a/exercises/12-Map_a_list/test.py b/exercises/12-Map_a_list/test.py index 1980cf57..6fffeeb8 100644 --- a/exercises/12-Map_a_list/test.py +++ b/exercises/12-Map_a_list/test.py @@ -1,7 +1,7 @@ import io, sys, pytest, os, re path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -@pytest.mark.it("Convert Celsius to Fahrenheit and print to console") +@pytest.mark.it("Convert celsius to fahrenheit and print to console") def test_dict(capsys, app): import app captured = capsys.readouterr() @@ -11,4 +11,4 @@ def test_dict(capsys, app): def test_if_loo(): f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py') content = f.read() - assert content.find("map") > 0 \ No newline at end of file + assert content.find("map") > 0 diff --git a/exercises/12.1-more_mapping/README.es.md b/exercises/12.1-more_mapping/README.es.md index 46521fce..5c67b4f2 100644 --- a/exercises/12.1-more_mapping/README.es.md +++ b/exercises/12.1-more_mapping/README.es.md @@ -1,31 +1,27 @@ # `12.1` More mapping -El método `map()` de una lista, llama a una función por cada valor en la lista y, luego, entrega una nueva lista con los valores modificados. +El método `map()` llama a una función por cada valor en la lista y, luego, devuelve una nueva lista con los valores modificados. ```py -#incrementando en 1 -def values_list(number) { - return number + 1 -} +def increment_by_one(number): + return number + 1 my_list = [1, 2, 3, 4] -result = map(values_list, my_list) #retorna [2, 3, 4, 5] +result = map(increment_by_one, my_list) # returns [2, 3, 4, 5] ``` ## 📝 Instrucciones: -1. Crear una función llamada `increment_by_one` que multiplicará cada número por 3. +1. Crear una función llamada `multiply_by_three` que multiplicará cada número por 3. -2. Pasa un argumento a la función. +2. Usa la función `map()` de la lista para ejecutar la función `multiply_by_three` en cada valor de la lista. -3. Usa la función `map()` de la lista para ejecutar la función `increment_by_one` a través de cada valor en la lista. +3. Almacena la nueva lista en una variable llamada `new_list` e imprime los nuevos valores. -4. Almacena la nueva lista en una nueva llamada `new_list` e imprime los nuevos valores. +## 💡 Pistas: -## 💡 Pista: ++ La función `map()` aplicará la función especificada por parámetro a cada elemento de tu lista. -+ La función cogerá un parámetro con el elemento original y lo transformará e insertará en una nueva lista (`new_list`). - -+ Recuerda que tu función debe devolver cada nuevo elemento para almacenarlo en la nueva lista (`new_list`). ++ Recuerda almacenar tu resultado en la nueva lista (`new_list`). diff --git a/exercises/12.1-more_mapping/README.md b/exercises/12.1-more_mapping/README.md index b986de39..14572f88 100644 --- a/exercises/12.1-more_mapping/README.md +++ b/exercises/12.1-more_mapping/README.md @@ -1,29 +1,25 @@ # `12.1` More mapping -The list `map()` method calls a function for each value in a list and then outputs a new list with the modified values. +The `map()` method calls a function for each value in a list and then outputs a new list with the modified values. ```py -#incrementByOne -def values_list(number) { - return number + 1 -} +def increment_by_one(number): + return number + 1 my_list = [1, 2, 3, 4] -result = map(values_list, my_list) #returns [2, 3, 4, 5] +result = map(increment_by_one, my_list) # returns [2, 3, 4, 5] ``` -## 📝Instructions: +## 📝 Instructions: -1. Create a function named `increment_by_one` that will multiply each number by 3. +1. Create a function named `multiply_by_three` that will multiply each number by 3. -2. Use the list `map()` function to run the `increment_by_one` function through each value in the list. +2. Use the list `map()` function to run the `multiply_by_three` function through each value in the list. 3. Store the new list in a variable named `new_list` and `print()` the new values. -## 💡 Hint: - -+ The function will take a parameter with the original item being transformed and added into the new list. - -+ Remember that your function must return each of the new items to be stored into the new list. +## 💡 Hints: ++ The `map()` function will apply the specified function to every item in your list. ++ Remember to store your result in the `new_list`. diff --git a/exercises/12.1-more_mapping/app.py b/exercises/12.1-more_mapping/app.py index 073c5a78..c5d1ca14 100644 --- a/exercises/12.1-more_mapping/app.py +++ b/exercises/12.1-more_mapping/app.py @@ -1,5 +1,5 @@ -myNumbers = [23,234,345,4356234,243,43,56,2] +my_numbers = [23,234,345,4356234,243,43,56,2] -#Your code go here: +# Your code here -print(new_list) \ No newline at end of file +print(new_list) diff --git a/exercises/12.1-more_mapping/solution.hide.py b/exercises/12.1-more_mapping/solution.hide.py new file mode 100644 index 00000000..cffe7a81 --- /dev/null +++ b/exercises/12.1-more_mapping/solution.hide.py @@ -0,0 +1,9 @@ +my_numbers = [23,234,345,4356234,243,43,56,2] + +# Your code here +def multiply_by_three(number): + return number * 3 + +new_list = list(map(multiply_by_three, my_numbers)) + +print(new_list) diff --git a/exercises/12.1-more_mapping/test.py b/exercises/12.1-more_mapping/test.py index 876dbb5e..753927e5 100644 --- a/exercises/12.1-more_mapping/test.py +++ b/exercises/12.1-more_mapping/test.py @@ -1,7 +1,7 @@ import io, sys, pytest, os, re path = os.path.dirname(os.path.abspath(__file__))+'/app.py' -@pytest.mark.it("Result of multiply by 3") +@pytest.mark.it("Result of multiply_by_three must be correct") def test_multp(capsys, app): import app captured = capsys.readouterr() @@ -13,12 +13,12 @@ def test_map(): content = f.read() assert content.find("map") > 0 -@pytest.mark.it("Create the function increment_by_one") +@pytest.mark.it("Create the function multiply_by_three") def test_variable_exists(app): try: - app.increment_by_one + app.multiply_by_three except AttributeError: - raise AttributeError("The function 'increment_by_one' should exist on app.py") + raise AttributeError("The function 'multiply_by_three' should exist on app.py") @pytest.mark.it("Create the variable new_list") def test_variable_new_list(app):