Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73aeec4

Browse files
Merge pull request #53 from josemoracard/jose3-05-defining-vs-calling-a-function
exercise 05-defining-vs-calling-a-function
2 parents aba1fda + 8bfb202 commit 73aeec4

File tree

5 files changed

+34
-48
lines changed

5 files changed

+34
-48
lines changed

‎exercises/05-Defining-vs-Calling-a-function/README.es.md‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# `05` Definir vs llamar a una función
1+
# `05` Defining vs Calling a Function
22

3-
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.
3+
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.
44

55
Para definir una función necesitamos escribir esta fórmula básica de código:
66

77
```python
8-
def myFunctionName(parameter, parameter2, ...parameterX):
9-
# codigo de la función aquí
10-
return something
8+
def nombre_de_funcion(parametro1, parametro2, ...parametroX):
9+
# Código de la función aquí
10+
return algo
1111
```
1212

1313
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
1616

1717
*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).
1818

19-
Nombres de ejemplo: `add_two_integers` (suma dos números enteros), `calculate_taxes` (calcular impuestos), `get_random_number` (obtener número aleatorio), etc.
19+
Nombres de ejemplo: `add_two_integers` (suma dos números enteros), `calculate_taxes` (calcular impuestos), `get_random_number` (obtener número aleatorio), etc.
2020

21-
**Parámetros:** puedes definir tantos parámetros como desees, más aún, si los necesitas.
21+
**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.
2222

23-
La cantidad de parámetros dependerá de las operaciones realizadas dentro de la función.
24-
25-
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).
23+
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).
2624

2725
**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).
2826

@@ -34,7 +32,7 @@ Ejemplo de una función:
3432

3533
```python
3634
def concatenate_number_to_string(local_number, local_string):
37-
local_variable = local_string+""+str(local_number)
35+
local_variable = local_string+str(local_number)
3836
return local_variable
3937
```
4038

‎exercises/05-Defining-vs-Calling-a-function/README.md‎

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,47 @@
22
tutorial: "https://www.youtube.com/watch?v=fz4ttmwZWuc"
33
---
44

5-
# `05` Defining vs Calling a function
5+
# `05` Defining vs Calling a Function
66

7-
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.
7+
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.
88

9-
To define a function we need to write this basic code formula:
9+
To define a function, we need to write this basic code formula:
1010

1111
```python
12-
def myFunctionName(parameter, parameter2, ...parameterX):
13-
# the function code here
12+
def my_function_name(parameter1, parameter2, ...parameterX):
13+
# The function code here
1414
return something
1515
```
1616

1717
The word `def` is a reserved word in Python, this means it is only used to define a function.
1818

19-
**The name** of the function could be anything you like.
20-
Tip: use a descriptive name (don't be cheap with words,
21-
use as many as you need) this way you will understand what the function
22-
does -and returns-.
23-
Example names: add_two_integers , calculate_taxes , get_random_number, etc.
19+
**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-.
2420

25-
**Parameters:** you can define as many parameters as you like or need.
26-
The amount of parameters will depend on the operations done inside the function,
27-
I.E: if the function is adding two integers `(3 + 4)` this means the function
28-
will need two parameters (one for each integer).
21+
Example names: `add_two_integers`, `calculate_taxes`, `get_random_number`, etc.
2922

30-
**Scope:** All the code that the function will contain need to be indented
31-
one tab to the right, anything on a different indentation
32-
won't be considered as part of the function,
33-
this is called **the scope**, and it could be local (inside the function)
34-
and global (outside of the function).
23+
**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).
3524

36-
**The Return**: not every function needs to return something, but it is recommended that it does.
37-
Tip: returning `None` is a good default for when you, still, don't know if you need to return something.
25+
**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).
26+
27+
**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.
3828

3929
Example of a function:
4030

4131
```python
4232
def concatenate_number_to_string(local_number, local_string):
43-
local_variable = local_string+""+str(local_number)
33+
local_variable = local_string+str(local_number)
4434
return local_variable
4535
```
4636

4737

48-
# 📝 Instructions:
38+
## 📝 Instructions:
4939

5040
1. Define a function called `multi`.
5141

5242
2. The `multi` function receives two numbers.
5343

5444
3. Return the result of the multiplication between them.
5545

56-
## 💡 Hint
46+
## 💡 Hint:
5747

58-
+ Remember to add the `return` line. Every function should return something, in this case it should be the result of the multiplication.
48+
+ Remember to add the `return` line. Every function should return something, in this case, it should be the result of the multiplication.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Define the function called "multi" that expects 2 parameters:
1+
# Define below the function called "multi" that expects 2 parameters
22

3-
# don't edit anything below this line
3+
# Don't edit anything below this line
44
return_value = multi(7,53812212)
5-
print(return_value)
5+
print(return_value)
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Define the function called "multi" that expects 2 parameters:
2-
def multi(num1, num2):
1+
# Define below the function called "multi" that expects 2 parameters
2+
def multi(num1, num2):
33
total = num1 * num2
44
return total
5-
6-
7-
# don't edit anything below this line
5+
# Don't edit anything below this line
86
return_value = multi(7,53812212)
9-
print(return_value)
7+
print(return_value)

‎exercises/05-Defining-vs-Calling-a-function/tests.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io, sys, pytest, os, re, mock
22

3-
@pytest.mark.it("Create a function 'multi'")
3+
@pytest.mark.it("Create the function 'multi'")
44
def test_declare_variable():
55
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
66
with open(path, 'r') as content_file:
@@ -20,6 +20,6 @@ def test_for_return_something(capsys, app):
2020
def test_for_integer(capsys, app):
2121
assert app.multi(3,4) == 12
2222

23-
@pytest.mark.it('The function multi must receive two numbers and return their multiplication. Testing with different values.')
23+
@pytest.mark.it('The function multi must receive two numbers and return their multiplication. Testing with different values')
2424
def test_for_function_return(capsys, app):
25-
assert app.multi(10, 6) == 60
25+
assert app.multi(10, 6) == 60

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /