Skip to content

Commit 66f2361

Browse files
committed
ex 011 to 014
1 parent 5d0ab48 commit 66f2361

File tree

13 files changed

+88
-13
lines changed

13 files changed

+88
-13
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

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

0 commit comments

Comments
 (0)