Skip to content

Commit 5fccba7

Browse files
Merge pull request #40 from kiddopro/01-10
01 10
2 parents 6aca24e + f572bce commit 5fccba7

File tree

27 files changed

+219
-32
lines changed

27 files changed

+219
-32
lines changed

exercises/001-hello_world/README.es.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Cada idioma tiene funciones para integrarse con la consola, ya que al principio
66

77
Hoy en día, la impresión en la consola se utiliza sobre todo como herramienta de monitoreo, ideal para dejar un rastro del contenido de las variables durante la ejecución del programa.
88

9+
## 📝 Instrucciones:
10+
11+
1. Usa la función `print()` para escribir `"Hello World"` en la consola. Siéntete libre de intentar otras cosas también.
12+
913
## Ejemplo:
1014

1115
```py
1216
print("How are you?")
1317
```
1418

15-
## 📝 Instrucciones:
16-
17-
1. Usa la función `print()` para escribir `"Hello World"` en la consola. Siéntete libre de intentar otras cosas también.
18-
1919
## 💡 Pista:
2020

2121
+ Video de 5 minutos sobre [la consola](https://www.youtube.com/watch?v=vROGBvX_MHQ)

exercises/001-hello_world/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Every language has a console, as it was the only way to interact with the users
66

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

9+
## 📝 Instructions:
10+
11+
1. Use the `print()` function to print `"Hello World"` on the console. Feel free to try other things as well.
12+
913
## Example:
1014

1115
```py
1216
print("How are you?")
1317
```
1418

15-
## 📝 Instructions:
16-
17-
1. Use the `print()` function to print `"Hello World"` on the console. Feel free to try other things as well.
18-
1919
## 💡 Hint:
2020

2121
+ 5 minutes video about [the console](https://www.youtube.com/watch?v=1RlkftxAo-M)

exercises/002-sum_of_three_numbers/README.es.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
## Ejemplo de entrada:
88

9-
+ 2
10-
+ 3
11-
+ 6
9+
```py
10+
2
11+
3
12+
6
13+
```
1214

1315
## Ejemplo de salida:
1416

15-
+ 11
17+
```py
18+
11
19+
```
1620

exercises/002-sum_of_three_numbers/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
## Example input:
88

9-
+ 2
10-
+ 3
11-
+ 6
9+
```py
10+
2
11+
3
12+
6
13+
```
1214

1315
## Example output:
1416

15-
+ 11
17+
```py
18+
11
19+
```
1620

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Complete the function to return the area of the triangle.
2+
def area_of_triangle(arg1, arg2):
3+
#your code here, please remove the "None"
4+
return arg1 * arg2 / 2
5+
6+
# Testing your function
7+
print(area_of_triangle(3, 5))

exercises/003-area_of_right_triangle/test.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import io, sys, os, pytest, json, mock
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
54
@pytest.mark.it('The function area_of_triangle should exist')
6-
def test_function_exists(capsys):
5+
def test_function_exists(capsys, app):
76
try:
8-
import app
97
app.area_of_triangle
108
except AttributeError:
119
raise AttributeError("The function 'area_of_triangle' should exist on app.py")
1210

11+
@pytest.mark.it('The function must return something')
12+
def test_function_returns(capsys, app):
13+
result = app.area_of_triangle(1, 2)
14+
assert result != None
15+
16+
@pytest.mark.it('The function must return a number')
17+
def test_function_return_type(capsys, app):
18+
result = app.area_of_triangle(1,2)
19+
assert type(result) == type(1*2/2)
20+
1321
@pytest.mark.it('The solution should return the expected output. Testing with 3 and 5')
1422
def test_convert_inputs(capsys, app):
1523
result = app.area_of_triangle(3, 5)
1624
assert result == 7.5
1725

18-
@pytest.mark.it('The solution should return the expected output. Testing with 4 and 6')
19-
def test_convert_inputs(capsys, app):
20-
result = app.area_of_triangle(4, 6)
21-
assert result == 12
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Complete the function below to print the output per the example.
2+
def hello_name(name):
3+
4+
return "Hello, "+name+"!"
5+
6+
#Invoke the function with your name as the function's argument.
7+
print(hello_name("Bob"))

exercises/004-hello_harry/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.hello_name)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
result = app.hello_name('test')
10+
assert result != None
11+
12+
@pytest.mark.it('The function must return a string')
13+
def test_function_return_type(capsys, app):
14+
result = app.hello_name('test')
15+
assert type(result) == type('')
16+
717
@pytest.mark.it('The function hello_name must accept 1 parameter and return the correct output')
818
def test_for_file_output(capsys, app):
919
assert app.hello_name('a') == "Hello, a!"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#Complete the function to return the previous and next number of a given numner.".
2+
def previous_next(num):
3+
return (num-1, num+1)
4+
5+
6+
#Invoke the function with any interger at its argument.
7+
print(previous_next(179))

exercises/005-previous_and_next/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.previous_next)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
assert app.previous_next(6) != None
10+
11+
@pytest.mark.it('The function return a tuple')
12+
def test_function_return_type(capsys, app):
13+
result = app.previous_next(6)
14+
assert type(result) == type((1,2))
15+
716
@pytest.mark.it('The function previous_next must return the correct output')
817
def test_for_file_output(capsys, app):
918
assert app.previous_next(6) == (5, 7)

exercises/006-apple_sharing/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `007` apple sharing
1+
# `006` apple sharing
22

33
## 📝 Instrucciones:
44

exercises/006-apple_sharing/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# `007` apple sharing
1+
# `006` apple sharing
22

33
## 📝 Instructions:
44

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Complete the function to return:
2+
#1) How many apples each single student will get.
3+
#2) How many apples wil remain in the basket.
4+
#Hint: You can resolve this exercise either importing the math module or without it
5+
def apple_sharing(n,k):
6+
7+
return (round(k/n),k%n)
8+
9+
10+
11+
#Print the two answer per the example output.
12+
print(apple_sharing(6,50))

exercises/006-apple_sharing/test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.apple_sharing)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
assert app.apple_sharing(10, 54) != None
10+
11+
@pytest.mark.it('The function must return a tuple')
12+
def test_function_return_type(capsys, app):
13+
result = app.apple_sharing(10, 54)
14+
assert type(result) == type((1,2))
15+
716
@pytest.mark.it('The function apple_sharing must return the correct output')
817
def test_for_file_output(capsys, app):
918
assert app.apple_sharing(10, 54) == (54//10, 54%10)

exercises/006.1-square_value_of_number/README.es.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
1. Escribe una función llamada `square()` que calcule el valor al cuadrado de un número
66

7+
## Ejemplo de entrada:
8+
9+
```py
10+
square(6)
11+
```
12+
13+
## Ejemplo de salida:
14+
15+
```py
16+
36
17+
```
718
## 💡 Pista:
819

920
+ Usa el operador `**`.

exercises/006.1-square_value_of_number/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
1. Write a function called `square()` that calculates the square value of a number.
66

7+
## Example input:
8+
9+
```py
10+
square(6)
11+
```
12+
13+
## Example output:
14+
15+
```py
16+
36
17+
```
18+
719
## 💡 Hint:
820

921
+ Using the `**` operator
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# your code here
2+
def square(num):
3+
return None
4+
5+
print(square(6))

exercises/006.1-square_value_of_number/test.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.square)
66

7-
@pytest.mark.it('The we tried 6 and it should return 36')
7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
assert app.square(2) != None
10+
11+
@pytest.mark.it('The function must return a number')
12+
def test_function_return_type(capsys, app):
13+
result = app.square(6)
14+
assert type(result) == type(1)
15+
16+
@pytest.mark.it('The function should return the square of the given number.')
817
def test_for_file_output(capsys, app):
918
assert app.square(6) == 6*6
1019

11-
@pytest.mark.it('The we tried 47 and it should return 2209')
20+
@pytest.mark.it('The function should return the square of the given number. Testing with 47.')
1221
def test_for_file_output(capsys, app):
1322
assert app.square(47) == 47*47
1423

exercises/007-hours_and_minutes/test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.hours_minutes)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
assert app.hours_minutes(60) != None
10+
11+
@pytest.mark.it('The function must return a tuple')
12+
def test_function_return_type(capsys, app):
13+
result = app.hours_minutes(60)
14+
assert type(result) == type((1,2))
15+
16+
@pytest.mark.it('The function must return a tuple with numbers')
17+
def test_for_file_output(capsys, app):
18+
result = app.hours_minutes(60)
19+
assert type(result[0]) == type(1) and type(result[1]) == type(1)
20+
721
@pytest.mark.it('The function hours_minutes must return the correct output for 60 secs')
822
def test_for_file_output(capsys, app):
923
assert app.hours_minutes(60) == (0, 1)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#Complete the funtion to compute how many seconds passed between the two timestamp.
2+
def two_timestamp(hr1,min1,sec1,hr2,min2,sec2):
3+
fisrt_hour = hr1 * 3600
4+
first_min = min1 * 60
5+
final_first = fisrt_hour + first_min + sec1
6+
second_hour = hr2 * 3600
7+
second_min = min2 * 60
8+
final_second = second_hour + second_min + sec2
9+
10+
return final_second - final_first
11+
12+
13+
#Invoke the fuction and pass two timestamps(6 intergers) as its argument.
14+
print(two_timestamp(1,1,1,2,2,2))

exercises/008-two_timestamps/test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.two_timestamp)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
result = app.two_timestamp(1,2,30,4,3,20)
10+
assert result != None
11+
12+
@pytest.mark.it('The function must return a number')
13+
def test_function_return_type(capsys, app):
14+
result = app.two_timestamp(1,2,30,4,3,20)
15+
assert type(result) == type(1)
16+
717
@pytest.mark.it('We tried passing (1,2,30,4,3,20) as parameters and the function did not return 10850. Keep Trying!')
818
def test_for_file_output(capsys, app):
919
assert app.two_timestamp(1,2,30,4,3,20) == ( (3 * 60) + (4 * 3600) + 20 )- ((2 * 60) + (1 * 3600) + 30)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Complete the function to return the tens digit and the ones digit of any interger.
2+
def two_digits(digit):
3+
aux = str(digit)
4+
return (int(aux[0]), int(aux[1]))
5+
6+
7+
8+
#Invoke the function with any interger as its argument.
9+
print(two_digits(79))

exercises/009-two_digits/test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,27 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.two_digits)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_function_return(capsys, app):
9+
assert app.two_digits(30) != None
10+
11+
@pytest.mark.it('The function must return a tuple')
12+
def test_function_return_type(capsys, app):
13+
result = app.two_digits(30)
14+
assert type(result) == type((1,2))
15+
16+
@pytest.mark.it('The function must return a tuple with numbers')
17+
def test_for_file_output(capsys, app):
18+
result = app.two_digits(30)
19+
assert type(result[0]) == type(1) and type(result[1]) == type(1)
20+
721
@pytest.mark.it('The function two_digits must return the left and right digits of a 2 digits integer')
822
def test_for_file_output(capsys, app):
9-
assert app.two_digits(30) == (30//10, 30%10)
23+
assert app.two_digits(30) == (3,0)
24+
25+
@pytest.mark.it('The function two_digits must return the left and right digits of a 2 digits integer. Testing with 45.')
26+
def test_for_file_output(capsys, app):
27+
assert app.two_digits(45) == (4,5)
1028

1129

1230

exercises/010-swap_digits/README.es.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ swap_digits(79)
1212

1313
## Ejemplo de salida:
1414

15-
+ 97
15+
```py
16+
97
17+
```
1618

1719
## 💡 Pistas:
1820

0 commit comments

Comments
 (0)