From 221f1d2dbc9f69490754f3b2e665d3721077ef6c Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:31:42 +0100 Subject: [PATCH 1/7] Update README.md --- .../README.md | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/README.md b/exercises/05-Defining-vs-Calling-a-function/README.md index 3a826e3..ae69c15 100755 --- a/exercises/05-Defining-vs-Calling-a-function/README.md +++ b/exercises/05-Defining-vs-Calling-a-function/README.md @@ -4,48 +4,38 @@ tutorial: "https://www.youtube.com/watch?v=fz4ttmwZWuc" # `05` Defining vs Calling a function -Functions will only exists if you or somebody else defines them... it is the only way the language compiler/interpreter knows they exist, therefore it's able to run them when you call them. +Functions will only exist if you or somebody else defines them; it is the only way the language compiler/interpreter knows they exist, therefore it's able to run them when you call them. -To define a function we need to write this basic code formula: +To define a function, we need to write this basic code formula: ```python -def myFunctionName(parameter, parameter2, ...parameterX): - # the function code here +def my_function_name(parameter1, parameter2, ...parameterX): + # The function code here return something ``` The word `def` is a reserved word in Python, this means it is only used to define a function. -**The name** of the function could be anything you like. -Tip: use a descriptive name (don't be cheap with words, -use as many as you need) this way you will understand what the function -does -and returns-. -Example names: add_two_integers , calculate_taxes , get_random_number, etc. +**The name** of the function could be anything you like. Tip: Use a descriptive name (don't be cheap with words, use as many as you need); this way, you will understand what the function does -and returns-. -**Parameters:** you can define as many parameters as you like or need. -The amount of parameters will depend on the operations done inside the function, -I.E: if the function is adding two integers `(3 + 4)` this means the function -will need two parameters (one for each integer). +Example names: `add_two_integers`, `calculate_taxes`, `get_random_number`, etc. -**Scope:** All the code that the function will contain need to be indented - one tab to the right, anything on a different indentation -won't be considered as part of the function, -this is called **the scope**, and it could be local (inside the function) -and global (outside of the function). +**Parameters:** You can define as many parameters as you like or need. The amount of parameters will depend on the operations done inside the function. I.E: If the function is adding two integers `(a + b)` this means the function will need two parameters (one for each integer). -**The Return**: not every function needs to return something, but it is recommended that it does. -Tip: returning `None` is a good default for when you, still, don't know if you need to return something. +**Scope:** All the code that the function will contain needs to be indented one tab to the right, anything on a different indentation won't be considered as part of the function. This is called **the scope**, and it could be local (inside the function) and global (outside the function). + +**The Return**: not every function needs to return something, but it is recommended that it does. Tip: returning `None` is a good default for when you still don't know if you need to return something. Example of a function: ```python def concatenate_number_to_string(local_number, local_string): - local_variable = local_string+""+str(local_number) + local_variable = local_string + str(local_number) return local_variable ``` -# 📝 Instructions: +## 📝 Instructions: 1. Define a function called `multi`. @@ -53,6 +43,6 @@ def concatenate_number_to_string(local_number, local_string): 3. Return the result of the multiplication between them. -## 💡 Hint +## 💡 Hint: + Remember to add the `return` line. Every function should return something, in this case it should be the result of the multiplication. From ddff8b17f44858f310477c9719744007d375175e Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:32:11 +0100 Subject: [PATCH 2/7] Update README.md --- exercises/05-Defining-vs-Calling-a-function/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/README.md b/exercises/05-Defining-vs-Calling-a-function/README.md index ae69c15..4d8287d 100755 --- a/exercises/05-Defining-vs-Calling-a-function/README.md +++ b/exercises/05-Defining-vs-Calling-a-function/README.md @@ -45,4 +45,4 @@ def concatenate_number_to_string(local_number, local_string): ## 💡 Hint: -+ Remember to add the `return` line. Every function should return something, in this case it should be the result of the multiplication. ++ Remember to add the `return` line. Every function should return something, in this case, it should be the result of the multiplication. From 1ab3115c68aeff5b97f52045d17bbdb333748c9f Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:32:23 +0100 Subject: [PATCH 3/7] Update README.md --- exercises/05-Defining-vs-Calling-a-function/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/README.md b/exercises/05-Defining-vs-Calling-a-function/README.md index 4d8287d..4d059b5 100755 --- a/exercises/05-Defining-vs-Calling-a-function/README.md +++ b/exercises/05-Defining-vs-Calling-a-function/README.md @@ -2,7 +2,7 @@ tutorial: "https://www.youtube.com/watch?v=fz4ttmwZWuc" --- -# `05` Defining vs Calling a function +# `05` Defining vs Calling a Function Functions will only exist if you or somebody else defines them; it is the only way the language compiler/interpreter knows they exist, therefore it's able to run them when you call them. From 6310ba496149e5f99ec5344ed436af29445d03e0 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:38:58 +0100 Subject: [PATCH 4/7] Update README.es.md --- .../README.es.md | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/README.es.md b/exercises/05-Defining-vs-Calling-a-function/README.es.md index d193398..0df4059 100644 --- a/exercises/05-Defining-vs-Calling-a-function/README.es.md +++ b/exercises/05-Defining-vs-Calling-a-function/README.es.md @@ -1,13 +1,13 @@ -# `05` Definir vs llamar a una función +# `05` Defining vs Calling a Function -Las funciones solo existen si tú u otra persona las define... es la única forma en que el compilador/intérprete de idiomas sabe que existen, por lo tanto, puede ejecutarlas cuando las llama. +Las funciones solo existen si tú u otra persona las define... es la única forma en que el compilador/intérprete de lenguaje sabe que existen, por lo tanto, puede ejecutarlas cuando las llamas. Para definir una función necesitamos escribir esta fórmula básica de código: ```python -def myFunctionName(parameter, parameter2, ...parameterX): - # codigo de la función aquí - return something +def nombre_de_funcion(parametro1, parametro2, ...parametroX): + # Código de la función aquí + return algo ``` La palabra `def` es una palabra reservada en Python, esto significa que solo se usa para definir una función. @@ -16,13 +16,11 @@ La palabra `def` es una palabra reservada en Python, esto significa que solo se *Consejo:* usa un nombre descriptivo (no intentes ahorrar palabras, usa tantas como necesites) de esta manera entenderás lo que hace la función (y lo que devuelve). -Nombres de ejemplo: `add_two_integers` (suma dos números enteros), `calculate_taxes` (calcular impuestos) , `get_random_number` (obtener número aleatorio), etc. +Nombres de ejemplo: `add_two_integers` (suma dos números enteros), `calculate_taxes` (calcular impuestos), `get_random_number` (obtener número aleatorio), etc. -**Parámetros:** puedes definir tantos parámetros como desees, más aún, si los necesitas. +**Parámetros:** puedes definir tantos parámetros como desees, más aún, si los necesitas. La cantidad de parámetros dependerá de las operaciones realizadas dentro de la función. -La cantidad de parámetros dependerá de las operaciones realizadas dentro de la función. - -Ejemplo: si la función está sumando dos enteros (3 + 4), esto significa que la función necesitará dos parámetros (uno para cada entero). +Ejemplo: si la función está sumando dos enteros (a + b), esto significa que la función necesitará dos parámetros (uno para cada entero). **Alcance:** Todo el código que contenga la función debe tener una sangría a la derecha, todo lo que esté en una sangría diferente no será considerado como parte de la función, a esto se llama **alcance**, y puede ser local (dentro de la función) y global (fuera de la función). @@ -34,7 +32,7 @@ Ejemplo de una función: ```python def concatenate_number_to_string(local_number, local_string): - local_variable = local_string+""+str(local_number) + local_variable = local_string + str(local_number) return local_variable ``` From 7e81a0ac3fc78e8066fdb9075372527df765a515 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:39:34 +0100 Subject: [PATCH 5/7] Update app.py --- exercises/05-Defining-vs-Calling-a-function/app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/app.py b/exercises/05-Defining-vs-Calling-a-function/app.py index 79b86d8..eedeae6 100755 --- a/exercises/05-Defining-vs-Calling-a-function/app.py +++ b/exercises/05-Defining-vs-Calling-a-function/app.py @@ -1,5 +1,5 @@ -# Define the function called "multi" that expects 2 parameters: +# Define below the function called "multi" that expects 2 parameters -# don't edit anything below this line +# Don't edit anything below this line return_value = multi(7,53812212) -print(return_value) \ No newline at end of file +print(return_value) From 473ab8f8b838709b30cca9a80c930d34759f2a72 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:40:39 +0100 Subject: [PATCH 6/7] Update solution.hide.py --- .../05-Defining-vs-Calling-a-function/solution.hide.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/solution.hide.py b/exercises/05-Defining-vs-Calling-a-function/solution.hide.py index 6a28c77..afa0209 100644 --- a/exercises/05-Defining-vs-Calling-a-function/solution.hide.py +++ b/exercises/05-Defining-vs-Calling-a-function/solution.hide.py @@ -1,9 +1,7 @@ -# Define the function called "multi" that expects 2 parameters: -def multi(num1 , num2): +# Define below the function called "multi" that expects 2 parameters +def multi(num1, num2): total = num1 * num2 return total - - -# don't edit anything below this line +# Don't edit anything below this line return_value = multi(7,53812212) -print(return_value) \ No newline at end of file +print(return_value) From 8bfb20273373895ed48f5d04ef29377f7ced1902 Mon Sep 17 00:00:00 2001 From: Jose Mora <109150320+josemoracard@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:41:23 +0100 Subject: [PATCH 7/7] Update tests.py --- exercises/05-Defining-vs-Calling-a-function/tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/exercises/05-Defining-vs-Calling-a-function/tests.py b/exercises/05-Defining-vs-Calling-a-function/tests.py index 35f9e6c..ab63ea7 100755 --- a/exercises/05-Defining-vs-Calling-a-function/tests.py +++ b/exercises/05-Defining-vs-Calling-a-function/tests.py @@ -1,6 +1,6 @@ import io, sys, pytest, os, re, mock -@pytest.mark.it("Create a function 'multi'") +@pytest.mark.it("Create the function 'multi'") def test_declare_variable(): path = os.path.dirname(os.path.abspath(__file__))+'/app.py' with open(path, 'r') as content_file: @@ -20,6 +20,6 @@ def test_for_return_something(capsys, app): def test_for_integer(capsys, app): assert app.multi(3,4) == 12 -@pytest.mark.it('The function multi must receive two numbers and return their multiplication. Testing with different values.') +@pytest.mark.it('The function multi must receive two numbers and return their multiplication. Testing with different values') def test_for_function_return(capsys, app): - assert app.multi(10, 6) == 60 \ No newline at end of file + assert app.multi(10, 6) == 60