Skip to content

exercises 01-hello-world to 04-Call-a-function #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions exercises/01-hello-world/README.es.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
# Aprende Funciones en Python!
# Welcome to Python Functions!

¡¡Nos estusiasma mucho tenerte aquí!! 🎉 😂
¡¡Nos entusiasma mucho tenerte aquí!! 🎉 😂

Presiona `Next →` en la esquina superior derecha cuando quieras empezar.

En este curso aprenderás los siguientes conceptos:

1. Cómo crear y llamar **funciones.**
1. Cómo crear y llamar funciones.

2. Construir tus primeras **funciones.**
2. Construir tus primeras funciones.

3. Sentirte cómod@ usando **funciones Lambda** en Python.
3. Practicar las funciones Lambda de Python.

4. Construir **funciones** con parámetros.
4. Construir funciones con parámetros.

5. Ejemplos de la vida real con **funciones**
5. Ejemplos de la vida real con funciones.

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

1. [Alejandro Sanchez (alesanchezr)](https://github.com/alesanchezr), contribution: (coder) :computer: (idea) 🤔, (build-tests) :warning:, (pull-request-review) :eyes: (build-tutorial) :white_check_mark: (documentation) :book:
2. [Paolo (plucodev)](https://github.com/plucodev), contribución: (bug reports) :bug: (coder) :computer:, (traducción) :earth_americas:
3. [Marco Gómez (marcogonzalo)](https://github.com/marcogonzalo), contribución: (bug reports) :bug:, (traducción) :earth_africa:
1. [Alejandro Sanchez (alesanchezr)](https://github.com/alesanchezr), contribution: (coder) 💻, (idea) 🤔, (build-tests) ⚠️, (pull-request-review) 🤓, (build-tutorial) ✅, (documentation) 📖
2. [Paolo (plucodev)](https://github.com/plucodev), contribución: (bug reports) 🐛, (coder) 💻, (traducción) 🌎
3. [Marco Gómez (marcogonzalo)](https://github.com/marcogonzalo), contribución: (bug reports) 🐛, (traducción) 🌎

This project follows the
[all-contributors](https://github.com/kentcdodds/all-contributors)
specification. Contributions of any kind are welcome!
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
26 changes: 12 additions & 14 deletions exercises/01-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@
intro: "https://www.youtube.com/watch?v=awa_yfGgy9s"
---

# Learn Python Functions!
# Welcome to Python Functions!

We are very excited to have you here !! 🎉 😂

Click `next` on the top right of this instructions when you are ready to start.
Click `Next →` on the top right of these instructions when you are ready to start.

During this course you will be learning the following concepts:
During this course, you will be learning the following concepts:

1. Learning how to create and call **functions.***
1. Learning how to create and call functions.

2. Building your first real **functions**
2. Building your first real functions.

3. Get comfortable using Python **Lambda Functions**
3. Get comfortable using Python Lambda Functions.

4. Construct **functions** with parameters.
4. Construct functions with parameters.

5. Real life examples for **functions**
5. Real life examples for functions.

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

1. [Alejandro Sanchez (alesanchezr)](https://github.com/alesanchezr), contribution: (coder) :computer: (idea) 🤔, (build-tests) :warning:, (pull-request-review) :eyes: (build-tutorial) :white_check_mark: (documentation) :book:
2. [Paolo (plucodev)](https://github.com/plucodev), contribution: (bug reports) :bug:, contribution: (coder), (translation) :earth_americas:
3. [Marco Gómez (marcogonzalo)](https://github.com/marcogonzalo), contribution: (bug reports) :bug:, (translation) :earth_africa:
1. [Alejandro Sanchez (alesanchezr)](https://github.com/alesanchezr), contribution: (coder) 💻, (idea) 🤔, (build-tests) ⚠️, (pull-request-review) 🤓, (build-tutorial) ✅, (documentation) 📖
2. [Paolo (plucodev)](https://github.com/plucodev), contribution: (bug reports) 🐛, (coder) 💻, (translation) 🌎
3. [Marco Gómez (marcogonzalo)](https://github.com/marcogonzalo), contribution: (bug reports) 🐛, (translation) 🌎

This project follows the
[all-contributors](https://github.com/kentcdodds/all-contributors)
specification. Contributions of any kind are welcome!
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome!
11 changes: 6 additions & 5 deletions exercises/02-Hello-World/README.es.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# `02` Hello World

En Python, usamos `print` para hacer que el computador escriba cualquier cosa que queramos (el contenido de una variable, un texto dado, etc.) en algo llamado `la consola`.
En Python, usamos **print** para hacer que el computador escriba cualquier cosa que queramos (el contenido de una variable, un string dado, etc.) en algo llamado "la consola".

Cada idioma tiene **funciones** para integrarse con la consola, ya que al principio era la única forma de interactuar con los usuarios (antes de que llegara Windows o MacOS o Linux). Hoy en día, la impresión en la consola se utiliza (`print`) sobre todo como herramienta de monitoreo, ideal para dejar un rastro del contenido de las variables durante la ejecución del programa.
Cada lenguaje tiene **funciones** para integrarse con la consola, ya que al principio era la única forma de interactuar con los usuarios (antes de que llegaran Windows, Linux o macOS).

Este es un ejemplo de cómo usarlo
Hoy en día, la impresión en la consola se utiliza, sobre todo, como herramienta de monitoreo y depuración, ideal para dejar un rastro del contenido de las variables durante la ejecución del programa.

Este es un ejemplo de cómo usarla:

```py
print("How are you?")
Expand All @@ -16,5 +18,4 @@ print("How are you?")

## 💡 Pista:

+ :video_camera: Puedes ver este breve video (5 minutos) sobre la consola:
https://www.youtube.com/watch?v=vROGBvX_MHQ
+ 📹 Puedes ver este breve video (2 minutos) sobre la consola: https://www.youtube.com/watch?v=vROGBvX_MHQ
12 changes: 6 additions & 6 deletions exercises/02-Hello-World/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ tutorial: "https://www.youtube.com/watch?v=voBO7a0KPtE"

# `02` Hello World

In Python, we use `print` to make the computer write anything we want (the content of a variable, a given string, etc.) in something called `the console`.
In Python, we use **print** to make the computer write anything we want (the content of a variable, a given string, etc.) in something called "the console".

Every language has **functions** to integrate with the console, as it was the only way to interact with the users at the beginning (before the Windows or Linux or MacOS arrived).
Every language has **functions** to integrate with the console, as it was the only way to interact with the users at the beginning (before Windows, Linux or macOS arrived).

Today, printing in the console is used mostly as a monitoring tool, ideal to leave a trace of the content of variables during the program execution.
Today, printing in the console is mostly used as a monitoring and debugging tool, ideal for leaving a trace of the content of variables during the program's execution.

This is an example of how to use it:

```py
print("How are you?")
```

## 📝 Instructions:

1. Use `print` to display `"Hello World"` on the console. Feel free to try other things as well.
1. Use `print()` to display `"Hello World"` on the console. Feel free to try other things as well.

## 💡 Hint:

+ :video_camera: You can watch this 5 minutes video about the console:
https://www.youtube.com/watch?v=vROGBvX_MHQ
+ 📹 You can watch this 2 minute video about the console: https://www.youtube.com/watch?v=vROGBvX_MHQ
2 changes: 1 addition & 1 deletion exercises/02-Hello-World/app.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# your code here
# Your code here
3 changes: 3 additions & 0 deletions exercises/02-Hello-World/solution.hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Your code here

print("Hello World")
14 changes: 7 additions & 7 deletions exercises/03-What-is-a-function/README.es.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# `03` ¿Qué es una función (function)?
# `03` What is a function?

Puedes ver una función como un **fragmento de código** que puedes encapsular entre llaves para poder usarla varias veces.
Puedes ver una función como un **fragmento de código** que puedes usar varias veces.

Por ejemplo, si queremos obtener la suma de dos números, podemos declarar una función llamada `sum` que devuelve la suma de `number1` y `number2`:

```python
def sum(number1,number2):
return number1 + number2
return number1 + number2
```

Después de declarar la función, podemos usarla tantas veces como queramos, así:
Expand All @@ -15,10 +15,10 @@ Después de declarar la función, podemos usarla tantas veces como queramos, as
total = sum(2,3)
total2 = sum(5,10)

print(total) # imprime 5 en la consola
print(total2) # imprime 15 en la consola
print(total) # Imprime 5 en la consola
print(total2) # Imprime 15 en la consola
```

# 📝 Instrucciones
## 📝 Instrucciones:

1. Calcula la suma entre **3445324** y **53454423** y asigna el resultado a una variable llamada `super_duper`
1. Calcula la suma entre `3445324` y `53454423` y asigna el resultado a una variable llamada `super_duper`.
12 changes: 6 additions & 6 deletions exercises/03-What-is-a-function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ For example: If we want to get the sum of two numbers, we can declare a function

```python
def sum(number1,number2):
return number1 + number2
return number1 + number2
```

After the function is declared we can use it as many times as we want, like this:
After the function is declared, we can use it as many times as we want, like this:

```python
total = sum(2,3)
total2 = sum(5,10)

print(total) # prints 5 on the console
print(total2) # prints 15 on the console
print(total) # Prints 5 on the console
print(total2) # Prints 15 on the console
```

# 📝 Instructions
## 📝 Instructions:

1. Please calculate the sum between **3445324** and **53454423** and assign the result to a variable called `super_duper`
1. Please calculate the sum between `3445324` and `53454423` and assign the result to a variable called `super_duper`.
1 change: 1 addition & 0 deletions exercises/03-What-is-a-function/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def sum(number1,number2):
return number1 + number2

# Your code here
total = sum(2,3)
print(total)
6 changes: 6 additions & 0 deletions exercises/03-What-is-a-function/solution.hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def sum(number1,number2):
return number1 + number2

# Your code here
super_duper = sum(3445324,53454423)
print(super_duper)
28 changes: 14 additions & 14 deletions exercises/04-Call-a-function/README.es.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
---
tutorial: "https://www.youtube.com/watch?v=NU5iW_bWwmY"
---
# `04` Llamando a una función
# `04` Calling a Function

Una función podría recibir 0 parámetros y tú puedes devolver algo siempre, incluso si no añades explícitamente el `return`.
Una función podría recibir 0 parámetros y devolverá algo siempre, incluso si no añades explícitamente el `return`.

:point_up: [Presiona aquí para saber más sobre funciones](https://content.breatheco.de/es/lesson/working-with-functions-python/)
👉 [Clic aquí para saber más sobre funciones](https://4geeks.com/es/lesson/working-with-functions-python-es).

Por ejemplo, una función que calcula el área de un cuadrado sería algo como esto:

```python
def calculate_area(length, edge):
return length * edge
def calculate_area(length, width):
return length * width
```

Si deseas usar esa función para calcular el área de un cuadrado con
Si deseas usar esa función para calcular el área de un cuadrado con:

```python
length = 3
edge = 6
width = 6
```

Tendrías que hacer algo como esto:

```python
area = calculate_area(3,6)
# El valor del área es 18
# El valor de 'area' sería 18
```

## 📝 Instrucciones:

1. Crea nuevas variables llamadas `squareArea1`, `square_area2`, `square_area3` y llama a la función `CalculateArea` 3 veces, un por cada cuadrado en la foto, utilizando las dimensiones de la figura, por ejemplo:
1. Crea nuevas variables llamadas `square_area1`, `square_area2`, `square_area3` y llama a la función `calculate_area` 3 veces, una por cada cuadrado en la foto, utilizando las dimensiones de la figura, por ejemplo:

```python
# para la primera figura:
# Para la primera figura:
square_area1 = calculate_area(4,4)
```

![img](http://i.imgur.com/VyoJRAL.png)
![Cuadrados](http://i.imgur.com/VyoJRAL.png)

## 💡 Pista:
## 💡 Pistas:

- Llama 3 veces a la función `calculate_area`, una por cada cuadrado, pasando la longitud y el borde de cada cuadrado.
- Llama 3 veces a la función `calculate_area`, una por cada cuadrado, pasando la longitud y el ancho de cada cuadrado.

+ :video_camera: [Video de 9 min sobre funciones en Python](https://www.youtube.com/watch?v=NE97ylAnrz4)
+ 📹 [Video de 9 min sobre funciones en Python](https://www.youtube.com/watch?v=NE97ylAnrz4).
20 changes: 10 additions & 10 deletions exercises/04-Call-a-function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@
tutorial: "https://www.youtube.com/watch?v=NU5iW_bWwmY"
---

# `04` Calling a function
# `04` Calling a Function

A function could receive zero parameters, and it always returns something, even if you don't explicitly add the `return` statement.

:point_up: [Click here to read more about functions](https://content.breatheco.de/lesson/working-with-functions-python)
👉 [Click here to read more about functions](https://4geeks.com/lesson/working-with-functions-python).

For example: a function that calculates the area of a square will be something like this:

```python
def calculate_area(length, edge):
return length * edge
def calculate_area(length, width):
return length * width
```

If you want to use that function to calculate the area of a square with:

```python
length = 3
edge = 6
width = 6
```

You need to do something like this:

```python
area = calculate_area(3,6)
# The value of area will be set to 18
# The value of 'area' will be set to 18
```

## 📝 Instructions:

1. Create a new variables named `square_area1`, `square_area2`, `square_area3` and call the function `calculate_area` three times one for each square in the picture, for example:
1. Create new variables named `square_area1`, `square_area2`, `square_area3` and call the function `calculate_area` three times, one for each square in the picture, for example:

```python
# For the first figure:
square_area1 = calculate_area(4,4)
```

![img](http://i.imgur.com/VyoJRAL.png)
![Squares](http://i.imgur.com/VyoJRAL.png)

## 💡 Hint:
## 💡 Hints:

+ Call the `calculate_area` function three times, one per each square, passing the length and edge of each square.

+ :video_camera: [9 min video about functions in python](https://www.youtube.com/watch?v=NE97ylAnrz4)
+ 📹 [9 min video about functions in Python](https://www.youtube.com/watch?v=NE97ylAnrz4).

6 changes: 3 additions & 3 deletions exercises/04-Call-a-function/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def calculate_area(length,edge):
return length * edge
def calculate_area(length, width):
return length * width

# Your code Below this line:
# Your code below this line
8 changes: 4 additions & 4 deletions exercises/04-Call-a-function/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def calculate_area(length,edge):
return length * edge
def calculate_area(length, width):
return length * width

# Your code Below this line:
# Your code below this line
square_area1 = calculate_area(4,4)
square_area2 = calculate_area(2,2)
square_area3 = calculate_area(5,5)
square_area3 = calculate_area(5,5)
8 changes: 4 additions & 4 deletions exercises/04-Call-a-function/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io, sys, pytest, os, re, mock

@pytest.mark.it("Create a function 'calculate_area'")
@pytest.mark.it("Create the function 'calculate_area'")
def test_declare_variable():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
Expand All @@ -16,7 +16,7 @@ def test_for_callable(capsys, app):
def test_for_integer(capsys, app):
assert isinstance(app.calculate_area(3,4), int)

@pytest.mark.it('We tried the function sum with a=3 and b=4 and it did not return 7')
@pytest.mark.it('We tried the function sum with length=3 and width=4 and it did not return 12')
def test_for_return(capsys, app):
assert app.calculate_area(3,4) == 12
assert app.calculate_area(5,4) == 20
Expand All @@ -43,10 +43,10 @@ def test_for_square_area_value2(capsys, app):
def test_for_square_area_value3(capsys, app):
assert app.square_area3 == 25

@pytest.mark.it("Create a function calculate_area must be called 3 times, one for each figure")
@pytest.mark.it("The function calculate_area must be called 3 times, one for each square")
def test_call_calculate_area():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
content = content_file.read()
regex = re.compile(r"=(\s*)calculate_area\s*\(")
assert bool(regex.search(content)) == True
assert bool(regex.search(content)) == True