Skip to content

Commit 1998019

Browse files
Merge pull request #41 from kiddopro/011-020
011 020
2 parents 5fccba7 + aab7042 commit 1998019

File tree

28 files changed

+241
-28
lines changed

28 files changed

+241
-28
lines changed

exercises/011-last_two_digits/README.es.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ last_two_digits(1234)
1212

1313
## Ejemplo de salida:
1414

15-
+ 34
16-
15+
```py
16+
34
17+
```
1718
## 💡 Pistas:
1819

1920
+ Si no sabes por donde comenzar este ejercicio, por favor, revisa la teoría en esta lección: https://snakify.org/lessons/integer_float_numbers/

exercises/011-last_two_digits/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
last_two_digits(1234)
1111
```
1212

13-
## Example output:
13+
## Example output:
1414

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

1719
## 💡 Hints:
1820

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Complete the function to print the last two digits of an interger greater than 9.
2+
def last_two_digits(num):
3+
if num > 9: return int(str(num)[-2:])
4+
else: return num
5+
6+
7+
#Invoke the function with any interger greater than 9.
8+
print(last_two_digits(1222))

exercises/011-last_two_digits/test.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22

33
@pytest.mark.it('The function last_two_digits must exist')
44
def test_for_functon_existence(capsys, app):
5-
assert callable(app.last_two_digits)
5+
assert callable(app.last_two_digits)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_for_return(capsys, app):
9+
assert app.last_two_digits(30) != None
10+
11+
@pytest.mark.it('The function must return a number')
12+
def test_for_output_type(capsys, app):
13+
assert type(app.last_two_digits(30)) == type(1)
14+
715
@pytest.mark.it('The function last_two_digits must return only the last 2 digits of a integer greater than 9')
816
def test_for_file_output(capsys, app):
917
if app.last_two_digits(30) > 9:

exercises/012-tens_digit/README.es.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ tens_digit(1234)
1212

1313
## Ejemplo de salida 1:
1414

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

1719
## Ejemplo de entrada 2:
1820

@@ -22,7 +24,9 @@ tens_digit(179)
2224

2325
## Ejemplo de salida 2:
2426

25-
+ 7
27+
```py
28+
7
29+
```
2630

2731
## 💡 Pistas:
2832

exercises/012-tens_digit/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
tens_digit(1234)
1111
```
1212

13-
## Example output 1:
13+
## Example output 1:
1414

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

1719
## Example input 2:
1820

@@ -22,7 +24,9 @@ tens_digit(179)
2224

2325
## Example output 2:
2426

25-
+ 7
27+
```py
28+
7
29+
```
2630

2731
## 💡 Hints:
2832

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 of a given interger
2+
def tens_digit(num):
3+
return (num // 10) % 10
4+
5+
6+
7+
8+
#Invoke the function with any interger.
9+
print(tens_digit(123))

exercises/012-tens_digit/test.py

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

7+
@pytest.mark.it('The function must return something')
8+
def test_for_return(capsys, app):
9+
assert app.tens_digit(123) != None
10+
11+
@pytest.mark.it('The function must return a number')
12+
def test_for_output_type(capsys, app):
13+
assert type(app.tens_digit(123)) == type(1)
14+
715
@pytest.mark.it('We tried to pass 854345 as parameter and it did not return 4!')
816
def test_for_file_output(capsys, app):
917
assert app.tens_digit(854345) == (854345 // 10)%10

exercises/013-sum_of_digits/README.es.md

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

1313
## Ejemplo de salida:
1414

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

1719
## 💡 Pistas:
1820

exercises/013-sum_of_digits/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44

55
1. Complete the `digits_sum()` function. Given a three-digit number, `digits_sum()` finds the sum of its digits.
66

7-
## Example input:
7+
## Example input:
88

99
```py
1010
digits_sum(123)
1111
```
1212

1313
## Example output:
1414

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

1719
## 💡 Hints:
1820

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Complete the function "digits_sum" so that it prints the sum of a three digit number.
2+
def digits_sum(num):
3+
aux = 0
4+
for x in str(num):
5+
aux= aux+int(x)
6+
return aux
7+
8+
9+
#Invoke the function with any three-digit-number
10+
#You can try other three-digit numbers if you want
11+
print(digits_sum(123))

exercises/013-sum_of_digits/test.py

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

7+
@pytest.mark.it('The function must return something')
8+
def test_for_return(capsys, app):
9+
assert app.digits_sum(123) != None
10+
11+
@pytest.mark.it('The function must return a number')
12+
def test_for_output_type(capsys, app):
13+
assert type(app.digits_sum(123)) == type(1)
14+
715
@pytest.mark.it('We tried to pass 854 as parameter and it did not return 17!')
816
def test_for_file_output(capsys, app):
917
assert app.digits_sum(854) == (854 //100)+(854 // 10)%10+ 854%10
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
def test_for_functon_existence(capsys, app):
55
assert callable(app.first_digit)
66

7+
@pytest.mark.it('The function must return something')
8+
def test_for_return(capsys, app):
9+
assert app.first_digit(1.2) != None
10+
11+
@pytest.mark.it('The function must return a number')
12+
def test_for_output_type(capsys, app):
13+
assert type(app.first_digit(1.2)) == type(1)
14+
715
@pytest.mark.it('We tried to pass 6.24 as parameter and it did not return 2!')
816
def test_for_file_output(capsys, app):
917
assert app.first_digit(6.24) == int(6.24 *10)%10

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))

exercises/017-total_cost/test.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@
66
def test_for_functon_existence(capsys, app):
77
assert callable(app.total_cost)
88

9+
@pytest.mark.it('The function must return something')
10+
def test_function_return(capsys, app):
11+
assert app.total_cost(15, 22, 4) != None
12+
13+
@pytest.mark.it('The function must return a tuple')
14+
def test_function_return_type(capsys, app):
15+
assert type(app.total_cost(15, 22, 4)) == type((60, 88))
16+
17+
@pytest.mark.it('The function must return a tuple of numbers')
18+
def test_function_return_type_parameters(capsys, app):
19+
result = app.total_cost(15, 22, 4)
20+
assert type(result[0]) == type(1) and type(result[1]) == type(1)
21+
922
@pytest.mark.it('We tried to pass 15, 22, 4 as parameters and it did not return (60, 88)!')
1023
def test_for_file_output(capsys, app):
11-
12-
assert app.total_cost(15, 22, 4) == ((((15*100)+22)*4)//100, (((15*100)+22)*4)%100)
24+
assert app.total_cost(15, 22, 4) == (60, 88)
25+
26+
@pytest.mark.it('We tried to pass 10, 15, 4 as parameters and it did not return (20, 30)!')
27+
def test_for_file_output2(capsys, app):
28+
assert app.total_cost(15, 22, 4) == (60, 88)
1329

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 number of day of the week for k'th day of year.
2+
def day_of_week(k):
3+
4+
return (3+k)%7
5+
6+
7+
8+
#Invoke function day_of_week with an interger between 0 and 6 (number for days of week)
9+
print(day_of_week(1))

exercises/018-day_of_week/test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66
def test_for_functon_existence(capsys, app):
77
assert callable(app.day_of_week)
88

9-
@pytest.mark.it('Something went wrong! We tried to pass 56 as parameter and it did not return 3!Keep trying!')
9+
@pytest.mark.it('The function must return something')
10+
def test_function_return(capsys, app):
11+
assert app.day_of_week(1) != None
12+
13+
@pytest.mark.it('The function must return a number')
14+
def test_function_return_type(capsys, app):
15+
assert type(app.day_of_week(1)) == type(1)
16+
17+
@pytest.mark.it('Something went wrong! We tried to pass 1 as parameter and it did not return 4! Keep trying!')
1018
def test_for_file_output(capsys, app):
19+
assert app.day_of_week(1) == 4
1120

12-
assert app.day_of_week(56) == (3+56)%7
21+
@pytest.mark.it('Something went wrong! We tried to pass 46 as parameter and it did not return 4! Keep trying!')
22+
def test_for_file_output2(capsys, app):
23+
assert app.day_of_week(46) == 0
1324

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Complete the function to return how many hrs and min are displayed on the 24th digital clock.
2+
def digital_clock(n):
3+
return ((n // 60), (n % 60))
4+
5+
#Invoke the function with any interger (seconds after midnight)
6+
print(digital_clock(150))

0 commit comments

Comments
 (0)