Skip to content

Commit aab7042

Browse files
committed
ex 011 to 020
1 parent 66f2361 commit aab7042

File tree

17 files changed

+155
-17
lines changed

17 files changed

+155
-17
lines changed

exercises/013-sum_of_digits/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_for_functon_existence(capsys, app):
66

77
@pytest.mark.it('The function must return something')
88
def test_for_return(capsys, app):
9-
assert app.digits_sum(123) == None
9+
assert app.digits_sum(123) != None
1010

1111
@pytest.mark.it('The function must return a number')
1212
def test_for_output_type(capsys, app):
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Complete the function to return the first digit to the right of the decimal point.
2+
import math
3+
def first_digit(num):
4+
return int(str(math.floor(num*10)/10)[-1])
5+
6+
7+
8+
9+
#Invoke the function with a positive real number. ex. 34.33
10+
print(first_digit(2.6))

exercises/014-digit_after_decimal_point/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_for_functon_existence(capsys, app):
66

77
@pytest.mark.it('The function must return something')
88
def test_for_return(capsys, app):
9-
assert app.first_digit(1.2) == None
9+
assert app.first_digit(1.2) != None
1010

1111
@pytest.mark.it('The function must return a number')
1212
def test_for_output_type(capsys, app):

exercises/015-car_route/README.es.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Un vehículo puede cubrir una distancia de `N` kilómetros por día ¿Cuántos d
99
## Ejemplo de entrada:
1010

1111
```py
12-
car_route(700,750)
12+
car_route(20,40)
1313
```
1414

1515
## Ejemplo de salida:

exercises/015-car_route/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A car can cover distance of `N` kilometers per day. How many days will it take t
99
## Example input:
1010

1111
```py
12-
car_route(700)
12+
car_route(20,40)
1313
```
1414

1515
## Example output:
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 amount of days it will take to cover a route.
2+
#HINT: You may need to import the math module for this exercise.
3+
import math
4+
def car_route(n,m):
5+
return int(math.ceil(m/n))
6+
7+
8+
#Invoke the function with two intergers.
9+
print(car_route())

exercises/015-car_route/test.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ def test_import_random():
1212
def test_for_functon_existence(capsys, app):
1313
assert callable(app.car_route)
1414

15-
@pytest.mark.it('We tried to pass 659 and 1857 as parameter and it did not return 3!')
15+
@pytest.mark.it('The function mus return something')
16+
def test_function_return(capsys, app):
17+
assert app.car_route(659, 1857) != None
18+
19+
@pytest.mark.it('The function must return a number')
20+
def test_function_return_type(capsys, app):
21+
assert type(app.car_route(659, 1857)) == type(1)
22+
23+
@pytest.mark.it('We tried to pass 20 and 40 as parameter and it did not return 2!')
1624
def test_for_file_output(capsys, app):
17-
assert app.car_route(659, 1857) == math.ceil(1857 / 659)
25+
assert app.car_route(20, 40) == 2
26+
27+
@pytest.mark.it('We tried to pass 20 and 900 as parameter and it did not return 45!')
28+
def test_for_file_output2(capsys, app):
29+
assert app.car_route(20, 900) == 45
1830

1931

2032

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Complete the function to return the respective number of the century
2+
#HINT: You may need to import the math module.
3+
import math
4+
def century(year):
5+
if year % 100 == 0:
6+
return math.floor(year/100)
7+
else:
8+
return math.floor(year/100 +1)
9+
10+
11+
12+
#Invoke the function with any given year.
13+
print(century(2022))

exercises/016-century/test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ def test_import_random():
1313
def test_for_functon_existence(capsys, app):
1414
assert callable(app.century)
1515

16-
@pytest.mark.it('We tried to pass 1801 as parameter and it did not return 19!')
16+
@pytest.mark.it('The function must return something')
17+
def test_function_return(capsys, app):
18+
assert app.century(19001) != None
19+
20+
@pytest.mark.it('The function must return a number')
21+
def test_function_return_type(capsys, app):
22+
assert type(app.century(19001)) == type(1)
23+
24+
@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 20!')
1725
def test_for_file_output(capsys, app):
18-
if app.century(1801) % 100 == 0:
19-
assert app.century(1801) == math.floor(1801/100)
20-
else:
21-
assert app.century(1801) == math.floor(1801/100 +1)
26+
assert app.century(2000) == 20
27+
28+
@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 21!')
29+
def test_for_file_output2(capsys, app):
30+
assert app.century(2001) == 21
31+
32+
@pytest.mark.it('We tried to pass 2000 as parameter and it did not return 21!')
33+
def test_for_file_output3(capsys, app):
34+
assert app.century(2101) == 22
2235

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Complete the function to return the total cost in dollars and cents of N cupcakes.
2+
#Remember you can return multiple parameters => return a, b
3+
def total_cost(d,c,n):
4+
return ((((d*100)+c)*n)//100, (((d*100)+c)*n)%100)
5+
6+
7+
8+
9+
#Invoke the function with three intergers: cost(dollars and cents) & number of cupcakes.
10+
print(total_cost(15,22,4))

0 commit comments

Comments
 (0)