Skip to content

Commit 6a90d33

Browse files
committed
ex 008 to 010
1 parent 34712a3 commit 6a90d33

File tree

8 files changed

+69
-5
lines changed

8 files changed

+69
-5
lines changed
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_for_file_output(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_for_file_output(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_for_file_output(capsys, app):
9+
assert app.two_digits(30) != None
10+
11+
@pytest.mark.it('The function must return a tuple')
12+
def test_for_file_output(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

exercises/010-swap_digits/README.md

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

1313
## Example output:
1414

15-
+ 97
16-
15+
```py
16+
97
17+
```
1718
## 💡 Hints:
1819

1920
+ If you don't know how to start solving this assignment, please, review a theory for this lesson: https://snakify.org/lessons/integer_float_numbers/

exercises/010-swap_digits/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Complete the fuction to return the swapped digits of a given two-digit-interger.
22
def swap_digits(num):
33
# Your code here
4-
4+
return None
55

66
#Invoke the function with any two digit interger as its argument
77
print(swap_digits(30))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Complete the fuction to return the swapped digits of a given two-digit-interger.
2+
def swap_digits(num):
3+
# Your code here
4+
aux = str(num)[1] +str(num)[0]
5+
6+
return int(aux)
7+
8+
9+
#Invoke the function with any two digit interger as its argument
10+
print(swap_digits(30))

0 commit comments

Comments
 (0)