Movatterモバイル変換


[0]ホーム

URL:


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

exercises 06-lambda-functions to 10-Array-Methods#55

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
37 commits
Select commitHold shift + click to select a range
b3fbd36
Update README.es.md
josemoracardNov 29, 2023
a96cd35
Update README.es.md
josemoracardNov 29, 2023
117bc32
Update README.md
josemoracardNov 29, 2023
b8b422f
Update README.md
josemoracardNov 29, 2023
e1d8fe2
Update README.es.md
josemoracardNov 29, 2023
4ed8919
Update README.md
josemoracardNov 29, 2023
d006197
Update app.py
josemoracardNov 29, 2023
e158501
Update tests.py
josemoracardNov 29, 2023
f7e459f
Update tests.py
josemoracardNov 29, 2023
0d2ba13
Update tests.py
josemoracardNov 29, 2023
0de3fbf
Create solution.hide.py
josemoracardNov 29, 2023
7877337
Update README.md
josemoracardNov 29, 2023
7c657c2
Update README.md
josemoracardNov 29, 2023
7f5cc84
Update README.es.md
josemoracardNov 29, 2023
a18d892
Update app.py
josemoracardNov 29, 2023
0280a20
Update solution.hide.py
josemoracardNov 29, 2023
daa03e4
Update tests.py
josemoracardNov 29, 2023
44a898b
Update README.md
josemoracardNov 29, 2023
930f773
Update README.md
josemoracardNov 29, 2023
08490fe
Update README.es.md
josemoracardNov 29, 2023
eaefd88
Update app.py
josemoracardNov 29, 2023
50e2eec
Update test.py
josemoracardNov 29, 2023
114310e
Create solution.hide.py
josemoracardNov 29, 2023
989a756
Update README.md
josemoracardNov 29, 2023
cecf0db
Update README.es.md
josemoracardNov 29, 2023
71fe9b0
Update solution.hide.py
josemoracardNov 29, 2023
af4d5fd
Update README.es.md
josemoracardNov 29, 2023
91c9d46
Update README.md
josemoracardNov 29, 2023
a5eafd9
Update README.md
josemoracardNov 29, 2023
3f6d997
Update README.md
josemoracardNov 29, 2023
8bfd0bc
Update README.es.md
josemoracardNov 29, 2023
4b35a98
Update solution.hide.py
josemoracardNov 29, 2023
3c02856
Update app.py
josemoracardNov 29, 2023
a229f30
Update README.md
josemoracardNov 29, 2023
355a13a
Update tests.py
josemoracardNov 29, 2023
b681c43
Update README.md
josemoracardNov 29, 2023
a438081
Update README.es.md
josemoracardNov 29, 2023
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
22 changes: 12 additions & 10 deletionsexercises/06-lambda-functions/README.es.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
# `06`FuncionesLambdaen Python
# `06` LambdaFunctions in Python

Una **función lambda** es una función con solo una línea de código y sin nombre.

Es un tipo de función muy especial en el mundo Python porque puedes usarla como una'pequeña utilidad' para una programación muy ágil:
Es un tipo de función muy especial en el mundo Python porque puedes usarla como una pequeña utilidad para una programación muy ágil:

```python
#declarando una función normal para una multiplicación
#Declarando una función normal para una multiplicación
def multiply(p1, p2):
return p1 * p2

#declarándola en una línea como una función lambda
#Declarándola en una línea como una función lambda
multiply = lambda p1,p2: p1 * p2
```

1. Las **funciones lambda** tiene que ser siempre muy pequeñas.
### 👉 Caracteristicas:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Caterísticas


2. Las **funciones lambda**pueden tener únicamente una línea.
+ Las **funciones lambda**tienen que ser siempre muy pequeñas.

3. Las **funciones lambda**no necesitan un `return`, se asume que lo que haya en esalínea devolverá un valor.
+ Las **funciones lambda**pueden tener únicamente unalínea.

4. Las **funciones lambda** pueden almacenarse en variables o ser pasadas como parámetro a otra función.
+ Las **funciones lambda** no necesitan un `return`, se asume que lo que haya en esa línea devolverá un valor.

+ Las **funciones lambda** pueden almacenarse en variables o ser pasadas como parámetro a otra función.


## 📝 Instrucciones:

1. Crea una variable llamada `is_odd`.

2. Asígnale una función lambda que devuelva `True` o `False` dependiendo de si un número dado es impar o no.
2. Asígnale una función**lambda** que devuelva `True` o `False` dependiendo de si un número dado es impar o no.

## 💡 Pista:

+ Así es como declararías una función normal:

```python
# Esta función retorna`True` si el número es impar
# Esta función retorna"True" si el número es impar
def is_odd(num):
return (num % 2) != 0
```
23 changes: 12 additions & 11 deletionsexercises/06-lambda-functions/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,42 +3,43 @@ tutorial: "https://www.youtube.com/watch?v=HACQ9uerCuE"
---


# `06` Lambdafunctions in Python
# `06` LambdaFunctions in Python

A **lambda function** is a function with just one line of code and no name.

It is a very special type offuncion in the world ofpython because you can use it as a small utility for very agile coding:
It is a very special type offunction in the world ofPython because you can use it as a small utility for very agile coding:

```python
#declaring a normalfuncion for multiplication
#Declaring a normalfunction for multiplication
def multiply(p1, p2):
return p1 * p2

#declaring it now like a one line lambda
#Declaring it now like a one line lambda function
multiply = lambda p1,p2: p1 * p2
```
:point_uo:Facts:

+ **Lambda fuctions** have to be always very small.
### 👉 Facts:

+ **Lambdafunction**can only have one line.
+ **Lambdafunctions**have to always be very small.

+ **Lambdafunction**doesn't need a `return` statement (it is assumed that it will return whatever is on thatone line).
+ **Lambdafunctions**can only haveone line.

+ **Lambda functions** can be stored in variables or passed as parameters to another function
+ **Lambda functions** don't need a `return` statement (it is assumed that it will return whatever is on that one line).

+ **Lambda functions** can be stored in variables or passed as parameters to another function.

## 📝 Instructions:

1. Create a variable called `is_odd`.

2. Assign a **lambda function** to it that returns `True` or `False` if a given number is odd.

## 💡Hint
## 💡Hint

+ Here is how you would declare it like a normal function:

```py
#this functionreturn True if a number is odd.
#This functionreturns True if a number is odd
def is_odd(num):
return num % 2 != 0
```
Expand Down
2 changes: 1 addition & 1 deletionexercises/06-lambda-functions/app.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
#your function here
#Your function here

3 changes: 3 additions & 0 deletionsexercises/06-lambda-functions/solution.hide.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
# Your function here

is_odd = lambda num: num % 2 != 0
6 changes: 3 additions & 3 deletionsexercises/06-lambda-functions/tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import io, sys, pytest, os, re, mock

@pytest.mark.it("Declare a function 'is_odd' as lambda")
@pytest.mark.it("Declare a functioncalled'is_odd' as lambda")
def test_declare_variable():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
Expand All@@ -13,12 +13,12 @@ def test_for_callable(capsys):
import app as app
assert callable(app.is_odd)

@pytest.mark.it('The function is_odd must receive one number and returntrue if is odd orfalse otherwise')
@pytest.mark.it('The function is_odd must receive one number and returnTrue ifthe numberis odd orFalse otherwise')
def test_for_integer(capsys):
import app as app
assert app.is_odd(3) == True

@pytest.mark.it('We tested the function with 2 and the result was not False')
def test_for_integer2(capsys):
import app as app
assert app.is_odd(2) == False
assert app.is_odd(2) == False
11 changes: 5 additions & 6 deletionsexercises/07-lambda-function-two/README.es.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
# `07`FuncionesLambda
# `07` Lambda Functions


**:point_up: Recuerda:**
### ☝ Recuerda:

Las funciones Lambda permiten una sintaxis corta para escribir expresiones de funciones.

```python
multy = lambda x, y: x * y
print(multy(2,2))
multiply = lambda x, y: x * y
print(multiply(2,2))
```

## 📝 Instrucciones:
Expand All@@ -18,4 +17,4 @@ print(multy(2,2))

## 💡 Pista:

+ Busca en Google "remove last letter form string python" (puedes usar los corchetes).
+ Busca en Google "como eliminar el último caracter de un string python" (puedes usar los corchetes).
16 changes: 8 additions & 8 deletionsexercises/07-lambda-function-two/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,23 +2,23 @@
tutorial: "https://www.youtube.com/watch?v=1HwmTkQPeMo"
---

# `07` Lambdafunctions
# `07` LambdaFunctions

**:point_up:Remember:**
### ☝Remember:

Lambda functionsallows a short syntax for writing function expressions.
Lambda functionsallow a short syntax for writing function expressions.

```python
multy = lambda x, y: x * y
print(multy(2,2))
multiply = lambda x, y: x * y
print(multiply(2,2))
```

## 📝 Instructions:

1. Create a lambda function called `rapid` it will take one string parameter.
1. Create a lambda function called `rapid`, which will take one string parameter.

2. Return the same string with the last letter removed.

## 💡 Hint
## 💡 Hint:

+ Google how to"remove last letterform string python" (you can use the square brackets).
+ Google"how to remove last letterfrom string python" (you can use the square brackets).
4 changes: 2 additions & 2 deletionsexercises/07-lambda-function-two/app.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@



#From this lineabove,plese do not change code below
print(rapid("bob")) #shouldprintbo
#Your codeabove,please do not change code below
print(rapid("bob")) # Shouldprint"bo"
5 changes: 2 additions & 3 deletionsexercises/07-lambda-function-two/solution.hide.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
rapid = lambda myStr: myStr[:-1]


# From this line above, plese do not change code below
print(rapid("bob")) #should print bo
# Your code above, please do not change code below
print(rapid("bob")) # Should print "bo"
4 changes: 2 additions & 2 deletionsexercises/07-lambda-function-two/tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import io, sys, pytest, os, re, mock

@pytest.mark.it("Declare a function 'rapid' as lambda")
@pytest.mark.it("Declare a functioncalled'rapid' as lambda")
def test_declare_variable():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
Expand All@@ -12,7 +12,7 @@ def test_declare_variable():
def test_for_callable(capsys):
from app import rapid

@pytest.mark.it('The function rapid must receive one string and return the samebut without the lastletter (make sure it\'s lowecase)')
@pytest.mark.it('The function rapid must receive one string and return the samestring without the lastcharacter')
def test_for_integer(capsys):
from app import rapid
assert rapid("maria") == "mari"
Expand Down
12 changes: 7 additions & 5 deletionsexercises/08-Function-that-returns/README.es.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
# `08`Funciones que devuelven
# `08`Functions that return

Es una muy buena práctica que las funciones devuelvan algo, incluso si es `None`.

Si tus funciones devuelven algo, puedes crear algoritmos que usen muchas funciones al mismo tiempo. Por ejemplo, en este caso en particular tenemos dos funciones disponibles:
Si tus funciones devuelven algo, puedes crear algoritmos que usen muchas funciones al mismo tiempo.

Por ejemplo, en este caso en particular tenemos dos funciones disponibles:

+ `dollar_to_euro`: que calcula el valor en euros de un valor dado en dólares.

Expand All@@ -12,12 +14,12 @@ Si tus funciones devuelven algo, puedes crear algoritmos que usen muchas funcion

1. Utilizando las dos funciones disponibles, imprime en la consola el valor de **137** dólares en yenes.

## 💡Pista:
## 💡Pistas:

Trabajandoal revés:
Trabajandodesde el final:

- Nuestro valor esperado está en yenes.

- Nuestra función disponible `euro_to_yen` proporcionará eso.

- Para llegar al euro utilizaremos la función disponible `dollar_to_euro`.
- Para llegar al euro utilizaremos la función disponible `dollar_to_euro`.
7 changes: 3 additions & 4 deletionsexercises/08-Function-that-returns/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,23 +8,22 @@ It is very good practice that all functions return something, even if it is `Non

With what your function returns, you can create algorithms that use multiple functions at the same time.

For example, in this particular case we have two functions available:
For example, in this particular case, we have two functions available:

+ `dollar_to_euro`: that calculates the value in euros of a given value in dollars.

+ `euro_to_yen`: calculates the value in yen of a given value in euros.


## 📝 Instructions:

1. Using the two functions available, print on the console the value of **137** dollars in yen.

## 💡Hint
## 💡Hints:

Working backwards:

- Our expected value is in yen.

- Our available function `euro_to_yen` will provide that.

- To getto euro we will use the available function `dollar_to_euro`.
- To getthe euros, we will use the available function `dollar_to_euro`.
6 changes: 3 additions & 3 deletionsexercises/08-Function-that-returns/app.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
def dollar_to_euro(dollar_value):
return dollar_value * 0.89
return dollar_value * 0.91

def euro_to_yen(euro_value):
return euro_value *124.15
return euro_value *161.70

####### ↓ YOUR CODE BELOW ↓ #######
####### ↓ YOUR CODE BELOW ↓ #######
12 changes: 12 additions & 0 deletionsexercises/08-Function-that-returns/solution.hide.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
def dollar_to_euro(dollar_value):
return dollar_value * 0.91

def euro_to_yen(euro_value):
return euro_value * 161.70

####### ↓ YOUR CODE BELOW ↓ #######

euros = dollar_to_euro(137)
yen = euro_to_yen(euros)

print(yen)
6 changes: 3 additions & 3 deletionsexercises/08-Function-that-returns/test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import io, sys, pytest, os, re, mock

@pytest.mark.it("Call the function dollar_to_euro passingthe137 dollars to get the amount inEuro")
@pytest.mark.it("Call the function dollar_to_euro passing 137 dollars to get the amount inEuros")
def test_declare_variable():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
Expand All@@ -9,7 +9,7 @@ def test_declare_variable():
assert bool(regex.search(content)) == True


@pytest.mark.it("Call the function euro_to_yen passing theEuro converted amount to get the amount in Yen")
@pytest.mark.it("Call the function euro_to_yen passing theEuros converted amount to get the amount in Yen")
def test_euro_to_yen():
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
with open(path, 'r') as content_file:
Expand All@@ -22,4 +22,4 @@ def test_euro_to_yen():
def test_for_file_output(capsys):
import app
captured = capsys.readouterr()
assert "15137.609500000002\n" == captured.out
assert "20159.139\n" == captured.out
12 changes: 7 additions & 5 deletionsexercises/09-Function-parameters/README.es.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
# `09`Parámetros de funciones
# `09`Function parameters

Puedes especificar tantos parámetros como desees en una función.

Expand All@@ -8,12 +8,14 @@ Los nombres de los parámetros no importan, pero debe ser **lo más explícito p

## 📝 Instrucciones:

+ Escribe la función `render_person` requerida para imprimir un string como el siguiente:
1. Escribe la función `render_person` requerida para imprimir un string como el siguiente:

```py
```text
Bob is a 23 years old male born in 05/22/1983 with green eyes
```

## 💡Pista
## 💡Pistas:

- Tienes que hacer una concatenación de string y devolver ese string.
+ Tienes que hacer una concatenación de string y devolver ese string.

+ También, puedes buscar en Google "como insertar variables en un string python".
10 changes: 6 additions & 4 deletionsexercises/09-Function-parameters/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,18 +6,20 @@ tutorial: "https://www.youtube.com/watch?v=uaiDxW4LJNA"

You can specify as many parameters as you want in a function.

As a developer you are going to find functions with even 6 or 7 parameters all the time.
As a developer, you are going to find functions with even 6 or 7 parameters all the time.

The names of the parameters don't matter, but you have to be **as explicit as you can** because these names will give clues to the other developers (or yourself in the future) about what is each parameter about.

## 📝 Instructions:

1. Please write the `render_person` function required to print aastring like the following:
1. Please write the `render_person` function required to print a string like the following:

```py
```text
Bob is a 23 years old male born in 05/22/1983 with green eyes
```

## 💡Hint
## 💡Hints:

+ You have to do some string concatenation and return that string.

+ Also, you can Google "how to insert variables into a string python".
6 changes: 3 additions & 3 deletionsexercises/09-Function-parameters/solution.hide.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
# Your code goes here:
def render_person(name,birthdate, eye_color, age,sex):
return name +" is a "+ str(age) +" years old " +sex +" born in " +birthdate + " with "+eye_color +" eyes"
def render_person(name,birth_date, eye_color, age,gender):
return name +" is a "+ str(age) +" years old " +gender +" born in " +birth_date + " with " +eye_color +" eyes"


# Do not edit below this line
print(render_person('Bob', '05/22/1983', 'green', 23, 'male'))
print(render_person('Bob', '05/22/1983', 'green', 23, 'male'))
Loading

[8]ページ先頭

©2009-2025 Movatter.jp