Skip to content

Commit

Permalink
Merge pull request #93 from josemoracard/jose4-05-user-inputed-values
Browse files Browse the repository at this point in the history
exercises 05-user-inputed-values to 19-bottles-of-milk
  • Loading branch information
alesanchezr authored Dec 6, 2023
2 parents edd518f + 597414d commit 95176e8
Show file tree
Hide file tree
Showing 70 changed files with 320 additions and 285 deletions.
6 changes: 3 additions & 3 deletions exercises/05-User-Inputed-Values/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Otra cosa genial de las variables es que no necesitas saber su valor para poder trabajar con ellas.

Por ejemplo, justo ahora la aplicación está preguntando la edad del usuario, y luego la imprime en la cónsola.
Por ejemplo, justo ahora la aplicación está preguntando la edad del usuario, y luego la imprime en la consola.

## 📝 Instrucciones:

1. Por favor, añade 10 años al valor de la variable `age`.

## 💡 Pista:
## 💡 Pistas:

+ Puedes buscar en Google "Como sumarle una cantidad a una variable de Python".

+ Recuerda que el contenido de la variable está siendo definido con lo que sea que el usuario coloque.
+ Recuerda que el contenido de la variable está siendo definido con lo que sea que el usuario coloque.
6 changes: 3 additions & 3 deletions exercises/05-User-Inputed-Values/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ For example, the application right now is prompting the user for its age, and th

1. Please add 10 years to the value of the age variable.

## 💡Hint
## 💡 Hints:

+ You can Google "how to add a number to a python variable".
+ You can Google "how to add a number to a Python variable".

+ Remember that the content of the variable its being previously filled with whatever the user inputs.
+ Remember that the content of the variable is being previously filled with whatever the user inputs.
2 changes: 1 addition & 1 deletion exercises/05-User-Inputed-Values/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_for_file_output(capsys):
regex = re.compile(pattern)
assert bool(regex.search(content)) == True

@pytest.mark.it("We tried with age 50 and it was supposed to return 60")
@pytest.mark.it("Testing with age 50 and it is supposed to return 60")
@mock.patch('builtins.input', lambda x: 50)
def test_plus_ten(stdin):
# f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
Expand Down
5 changes: 2 additions & 3 deletions exercises/06-String-Concatenation/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ Puedes pensar en este proceso como conectar dos o más vagones de tren. Si cada
En Python, puedes concatenar o unir dos o más strings usando el operador `+`. Así es como funciona:

```py

one = 'a'
two = 'b'
print(one + two) # esto imprimirá 'ab' en la consola.
print(one + two) # Esto imprimirá 'ab' en la consola.
```

Aquí, las variables `one` y `two` contienen los strings individuales `'a'` y `'b'`, respectivamente. Cuando usas el operador `+` entre ellos, actúa como un pegamento, uniendo los strings de extremo a extremo. En este caso, une `'a'` y `'b'`, dando como resultado el string concatenado `'ab'`, que se imprime en la consola.
Expand All @@ -20,4 +19,4 @@ Aquí, las variables `one` y `two` contienen los strings individuales `'a'` y `'


## 💡 Pista:
+ Si necesitas más explicación sobre como la **concatenación** funciona en Python, puedes ver este clip: https://www.youtube.com/watch?v=T1nyPuAhd1U&ab_channel=ProgramaResuelto (`ctrl + click` en el enlance para abrir el video)
+ Si necesitas más explicación sobre como funciona la **concatenación** en Python, puedes ver este clip: https://www.youtube.com/watch?v=T1nyPuAhd1U&ab_channel=ProgramaResuelto (`ctrl + click` en el enlace para abrir el video)
7 changes: 3 additions & 4 deletions exercises/06-String-Concatenation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ You can think of this process as similar to connecting two or more train cars. I
In Python, you can concatenate, or join together, two or more strings using the `+` operator. This is how it works:

```py

one = 'a'
two = 'b'
print(one + two) # this will print 'ab' on the console.
print(one + two) # This will print 'ab' on the console.
```

Here, the variables `one` and `two` hold the individual strings `'a'` and `'b'`. When you use the `+` operator between them, it acts like a glue, sticking the strings together end-to-end. In this case, it joins `'a'` and `'b'`, resulting in the concatenated string `'ab'`, which gets printed to the console.

## 📝 Instructions:
1. Set the values for `my_var1` and `my_var2` so that when concatenated, the code prints `Hello World` in the console.
1. Set the values for `my_var1` and `my_var2` so that, when concatenated, the code prints `Hello World` in the console.

## 💡 Hint:
+ If you need further explanation on how string **concatenation** works in python, you can watch this clip: https://www.youtube.com/watch?v=28FUVmWU_fA&ab_channel=PortfolioCourses (`ctrl + click` on the link to open the video)
+ If you need further explanation on how string **concatenation** works in Python, you can watch this clip: https://www.youtube.com/watch?v=28FUVmWU_fA&ab_channel=PortfolioCourses (`ctrl + click` on the link to open the video)
6 changes: 3 additions & 3 deletions exercises/06-String-Concatenation/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ✅ ↓ Set the values for my_var1 and my_var2 here ↓ ✅


## Don't change below this line
the_new_string = my_var1+' '+my_var2
print(the_new_string)
## Don't change anything below this line
the_new_string = my_var1 + ' ' + my_var2
print(the_new_string)
6 changes: 3 additions & 3 deletions exercises/06-String-Concatenation/solution.hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
my_var1 = "Hello"
my_var2 = "World"

## Don't change below this line
the_new_string = my_var1+' '+my_var2
print(the_new_string)
## Don't change anything below this line
the_new_string = my_var1 + ' ' + my_var2
print(the_new_string)
4 changes: 2 additions & 2 deletions exercises/06-String-Concatenation/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_my_var2_value():
from app import my_var2
assert my_var2.lower() == "world"

@pytest.mark.it("Variable my_var2 value should be 'World'")
@pytest.mark.it("Don't remove the_new_string variable")
def test_the_new_string_exists():
import app
try:
Expand All @@ -38,4 +38,4 @@ def test_the_new_string_exists():
@pytest.mark.it('Print "Hello World" on the console')
def test_for_file_output():
captured = buffer.getvalue()
assert "hello world\n" in captured.lower() #add \n because the console jumps the line on every print
assert "hello world\n" in captured.lower() #add \n because the console jumps the line on every print
10 changes: 4 additions & 6 deletions exercises/07-Create-a-Basic-HTML/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ Continuemos concatenando strings para generar un documento HTML básico...

## 📝 Instrucciones:

1. Crea una variable **html_document**.
1. Crea la variable `html_document`.

2. El código a la izquierda contiene 8 variables con diferentes valores de tipo *string*. Por favor, usa las variables concatenándolas entre ellas para establecer el valor de la variable **html_document** como nuevo string que tenga el contenido de un documento HTML típico (con las etiquetas HTML
en el orden correcto).
2. El código a la izquierda contiene 8 variables con diferentes valores de tipo *string*. Por favor, usa las variables concatenándolas entre ellas para establecer el valor de la variable `html_document` a la estructura típica de un documento HTML (con las etiquetas HTML en el orden correcto).

3. Luego, imprime el valor de **html_document** en la consola.
3. Luego, imprime el valor de `html_document` en la consola.

## 💡 Pista:

+ Resultado esperado:

```sh

```html
<html><head><title></title></head><body></body></html>
```

14 changes: 6 additions & 8 deletions exercises/07-Create-a-Basic-HTML/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@
tutorial: "https://www.youtube.com/watch?v=j14V-eS8mRg"
---

# `07` Create a basic HTML
# `07` Create a Basic HTML

Let's continue using string concatenation to generate HTML...

## 📝 Instructions:

1. Create a variable **html_document**.
1. Create the variable `html_document`.

2. The code on the left contains 8 variables with different string values, please use the variables concatenating them together to set the value of the variable **html_document**
a new string that has the content of a typical HTML document (with the HTML tags in the
right order).
2. The code on the left contains 8 variables with different string values, please use the variables concatenating them together to set the value of the variable `html_document`
to a new string that has the content of a typical HTML document (with the HTML tags in the right order).

3. Then, print the value of **html_document** on the console.
3. Then, print the value of `html_document` on the console.

## 💡 Hint:

+ Expected Result:

```sh

```html
<html><head><title></title></head><body></body></html>
```

4 changes: 2 additions & 2 deletions exercises/07-Create-a-Basic-HTML/solution.hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

# ✅ ↓ start coding below here ↓ ✅

html_document = e+c+g+a+f+h+d+b
print(html_document)
html_document = e + c + g + a + f + h + d + b
print(html_document)
20 changes: 10 additions & 10 deletions exercises/08.1-Your-First-If/README.es.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ La aplicación actual está preguntando cuánto dinero tiene el usuario. Una vez

## 📝 Instrucciones:

1. Si el usuario tiene más de $100, respondemos: "Give me your money!" (Dame tu dinero).
1. Si el usuario tiene más de $100, respondemos: "Give me your money!" (¡Dame tu dinero!).

2. Si el usuario tiene más de $50, respondemos: "Buy me some coffee you cheap!" (¡Comprame un café!).
2. Si el usuario tiene más de $50, respondemos: "Buy me some coffee, you cheap!" (¡Cómprame un café!).

3. Si el usuario tiene igual o menos de $50, respondemos: "You are a poor guy, go away!" (¡Eres pobre!).

## 💡 Pista:
## 💡 Pistas:

+ Usa un condicional `if/else` para verificar el valor de la variable `total`.
+ Usa un condicional `if...else` para verificar el valor de la variable `total`.

+ Puedes leer más al respecto [aquí](https://docs.python.org/3/tutorial/controlflow.html#if-statements).

+ Aquí tienes un recordatorio sobre los operadores relacionales:

| Operador | Descripción | Sintaxis |
|----------|------------------------------------------------------------------------------|----------|
| > | Mayor que: Verdadero si el operando izquierdo es mayor que el derecho | x > y |
| < | Menor que: Verdadero si el operando izquierdo es menor que el derecho | x < y |
| == | Igual a: Verdadero si ambos operandos son iguales | x == y |
| != | No igual a – Verdadero si los operandos no son iguales | x != y |
| >= | Mayor o igual que: Verdadero si el operando izquierdo es mayor o igual | x >= y |
| <= | Menor o igual que: Verdadero si el operando izquierdo es menor o igual | x <= y |
| > | Mayor que: True si el operando izquierdo es mayor que el derecho | x > y |
| < | Menor que: True si el operando izquierdo es menor que el derecho | x < y |
| == | Igual a: True si ambos operandos son iguales | x == y |
| != | No igual a: True si los operandos no son iguales | x != y |
| >= | Mayor o igual que: True si el operando izquierdo es mayor o igual | x >= y |
| <= | Menor o igual que: True si el operando izquierdo es menor o igual | x <= y |
26 changes: 13 additions & 13 deletions exercises/08.1-Your-First-If/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@
tutorial: "https://www.youtube.com/watch?v=x9wqa5WQZiM"
---

# `08.1` Your First if...
# `08.1` Your First If...

The current application is asking how much money the user has. Once the user inputs the amount, we need to **print** one of the following answers:

## 📝 Instructions:

1. If the user has more than $100, we answer: "Give me your money!".

2. If the user has more than $50, we answer: "Buy me some coffee you cheap!".
2. If the user has more than $50, we answer: "Buy me some coffee, you cheap!".

3. If the user has less or equal than $50, we answer: "You are a poor guy, go away!".
3. If the user has less than or equal to $50, we answer: "You are a poor guy, go away!".

## 💡 Hint:
## 💡 Hints:

+ Use an If/else statement to check the value of the `total` variable.
+ Use an `if...else` statement to check the value of the `total` variable.

+ Further information [here](https://docs.python.org/3/tutorial/controlflow.html#if-statements).

+ Here's a quick reminder on relational operators:

| Operator | Description | Syntax |
|----------|--------------------------------------------------------------------|-----------|
| > | Greater than: True if the left operand is greater than the right | x > y |
| < | Less than: True if the left operand is less than the right | x < y |
| == | Equal to: True if both operands are equal | x == y |
| != | Not equal toTrue if operands are not equal | x != y |
| >= | Greater than or equal to: True if left operand is greater or equal | x >= y |
| <= | Less than or equal to: True if left operand is less than or equal | x <= y |
| Operator | Description | Syntax |
|----------|------------------------------------------------------------------------|-----------|
| > | Greater than: True if the left operand is greater than the right | x > y |
| < | Less than: True if the left operand is less than the right | x < y |
| == | Equal to: True if both operands are equal | x == y |
| != | Not equal to: True if operands are not equal | x != y |
| >= | Greater than or equal to: True if the left operand is greater or equal | x >= y |
| <= | Less than or equal to: True if the left operand is less or equal | x <= y |
4 changes: 2 additions & 2 deletions exercises/08.1-Your-First-If/solution.hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
if total > 100:
print("Give me your money!")
elif total > 50:
print("Buy me some coffee you cheap!")
print("Buy me some coffee, you cheap!")
else:
print("You are a poor guy, go away!")
print("You are a poor guy, go away!")
18 changes: 9 additions & 9 deletions exercises/08.1-Your-First-If/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,37 @@ def test_for_output_when_101(stdin, capsys, app):
captured = capsys.readouterr()
assert "Give me your money!\n" in captured.out

@pytest.mark.it("When input exactly 100 should print: Buy me some coffee you cheap ")
@pytest.mark.it("When input exactly 100 should print: Buy me some coffee, you cheap!")
def test_for_output_when_100(capsys, app):
with mock.patch('builtins.input', lambda x: 100):
app()
captured = capsys.readouterr()
assert "Buy me some coffee you cheap!\n" in captured.out
assert "Buy me some coffee, you cheap!\n" in captured.out

@pytest.mark.it("When input is 99 should print: Buy me some coffee you cheap ")
@pytest.mark.it("When input is 99 should print: Buy me some coffee, you cheap!")
def test_for_output_when_99(capsys, app):
with mock.patch('builtins.input', lambda x: 99):
app()
captured = capsys.readouterr()
assert "Buy me some coffee you cheap!\n" in captured.out
assert "Buy me some coffee, you cheap!\n" in captured.out

@pytest.mark.it("When input is 51 should print: Buy me some coffee you cheap ")
@pytest.mark.it("When input is 51 should print: Buy me some coffee, you cheap!")
def test_for_output_when_51(capsys, app):
with mock.patch('builtins.input', lambda x: 51):
app()
captured = capsys.readouterr()
assert "Buy me some coffee you cheap!\n" in captured.out
assert "Buy me some coffee, you cheap!\n" in captured.out

@pytest.mark.it("When input exactly 50 should print: You are a poor guy, go away")
@pytest.mark.it("When input exactly 50 should print: You are a poor guy, go away!")
def test_for_output_when_50(capsys, app):
with mock.patch('builtins.input', lambda x: 50):
app()
captured = capsys.readouterr()
assert "You are a poor guy, go away!\n" in captured.out

@pytest.mark.it("When input less than 50 should print: You are a poor guy, go away")
@pytest.mark.it("When input less than 50 should print: You are a poor guy, go away!")
def test_for_output_when_49(capsys, app):
with mock.patch('builtins.input', lambda x: 49):
app()
captured = capsys.readouterr()
assert "You are a poor guy, go away!\n" in captured.out
assert "You are a poor guy, go away!\n" in captured.out
8 changes: 4 additions & 4 deletions exercises/08.2-How-Much-The-Wedding-Costs/README.es.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `08.2` Cuánto costará la boda (if...else)
# `08.2` How Much The Wedding Costs (if...else)

Aquí tenemos una tabla de precios de una compañía de catering de bodas:

Expand All @@ -9,16 +9,16 @@ Aquí tenemos una tabla de precios de una compañía de catering de bodas:
| Hasta 200 personas | $15,000 |
| Más de 200 personas | $20,000 |

>Nota: Las cantidades en la tabla incluyen el número especificado. Por ejemplo, "Hasta 50 personas" incluye exactamente 50 personas.
> Nota: Las cantidades en la tabla incluyen el número especificado. Por ejemplo, "Hasta 50 personas" incluye exactamente 50 personas.
## 📝 Instrucciones:

1. Completa el algoritmo que solicita al usuario el número de personas que asistirán a su boda e imprime el precio correspondiente en la consola.
2. Amplía el código proporcionado a la izquierda para cubrir todos los rangos posibles de invitados.
3. Asegúrate de que tu código calcule e imprima correctamente el precio en la consola según el input del usuario.

Por ejemplo, si la persona dice que `20` personas van a la boda, deberìa costar `$4,000` dólares.
Por ejemplo, si la persona dice que `20` personas van a la boda, debería costar `$4,000` dólares.

## 💡 Pista:

+ Usa if/else para dividir el código y definir el valor de la variable `price` de forma correcta.
+ Usa `if...else` para dividir el código y definir el valor de la variable `price` de forma correcta.
2 changes: 1 addition & 1 deletion exercises/08.2-How-Much-The-Wedding-Costs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ For example, if the user says that `20` people are attending to the wedding, it

## 💡 Hint:

+ Use if/else to divide your code and set the value of the `price` variable the right way.
+ Use `if...else` to divide your code and set the value of the `price` variable the right way.
8 changes: 5 additions & 3 deletions exercises/08.2-How-Much-The-Wedding-Costs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_for_print(capsys):
regex2 = re.compile(r"elif\s*")
assert bool(regex2.search(content)) == True


@pytest.mark.it("Between 101 and 200 guests sould be priced 15,000")
def test__between_100_and_200(capsys, app):
with mock.patch('builtins.input', lambda x: 200):
Expand All @@ -24,6 +25,7 @@ def test__between_100_and_200(capsys, app):
price = 15000
assert "Your wedding will cost "+str(price)+" dollars\n" in captured.out


@pytest.mark.it("Between 51 and 100 guests sould be priced 10,000")
def test_between_101_and_51(capsys, app):
with mock.patch('builtins.input', lambda x: 100):
Expand All @@ -33,18 +35,18 @@ def test_between_101_and_51(capsys, app):
assert "Your wedding will cost "+str(price)+" dollars\n" in captured.out


@pytest.mark.it("Less than 50 guests sould be priced 4,000")
@pytest.mark.it("Less than 50 guests, it should cost 4,000")
def test_less_than_50(capsys, app):
with mock.patch('builtins.input', lambda x: 50):
app()
captured = capsys.readouterr()
price = 4000
"Your wedding will cost "+str(price)+" dollars\n" in captured.out

@pytest.mark.it("More than 200 should be priced 20,000")
@pytest.mark.it("More than 200 guests, it should cost 20,000")
def test_t(capsys, app):
with mock.patch('builtins.input', lambda x: 201):
app()
captured = capsys.readouterr()
price = 20000
"Your wedding will cost "+str(price)+" dollars\n" in captured.out
"Your wedding will cost "+str(price)+" dollars\n" in captured.out
Loading

0 comments on commit 95176e8

Please sign in to comment.