Skip to content
30 changes: 18 additions & 12 deletions exercises/007-hours_and_minutes/README.es.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
# `007` hours and minutes
# `007` Hours and minutes

## 📝 Instrucciones:
En este ejercicio vamos a suponer que es medianoche, queremos que con la función `hours_minutes` que hemos previsto para tí, nos digas cuánto tiempo ha pasado desde entonces con los segundos que se introduzcan como parámetro.

1. Dado el número entero `N` - el número de segundos que pasan desde la medianoche ¿Cuántas horas y minutos completos han pasado desde la medianoche? *La función debe imprimir dos números: el número de horas (entre 0 y 23) y el número de minutos (entre 0 y 1339)*.
## 📝 Instrucciones:

## Ejemplo:
1. Completa la función para que retorne el resultado esperado.

* Si N = 3900 --> han pasado 3900 segundos desde la medianoche ,es decir, ahora es la 1:05 am.

+ El programa debe imprimir 1 65 --> 1 hora completa ha pasado desde la medianoche, 65 minutos completos han pasado desde la medianoche.
2. Realiza dos calculos con los segundos que se pasan por parámetro en la función para que uno calcule la hora según los segundos que han pasado y el otro para saber los minutos `(hora , minutos)`

## Ejemplo de entrada:
## Ejemplo 1:

```py
hours_minutes(3900)
output = hours_minutes(3900)
print(output) # (1, 5)
```

## Ejemplo de salida:
## Ejemplo 2:

+ (1, 65)
```py
output = hours_minutes(60)
print(output) # (0, 1)
```

## 💡 Pistas:

+ Si no sabes por donde partir este ejercicio por favor, revisa la teoría en esta lección: ttps://snakify.org/lessons/print_input_numbers/
+ Recuerda cuantos segundos hay en una hora (3600) y cuantos segundos en un minuto (60).

+ Si no sabes cómo empezar la solución a esta asignación, por favor, revisa la teoría en esta lección: https://snakify.org/lessons/print_input_numbers/

+ También puedes intentar paso a paso con trozos de la teoría: https://snakify.org/lessons/print_input_numbers/steps/1/

[comment]: <Solution: (secs//3600, secs//60)>
29 changes: 18 additions & 11 deletions exercises/007-hours_and_minutes/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
# `007` hours and minutes
# `007` Hours and Minutes

## 📝 Instructions:

1. Given the integer `N` - the number of seconds that is passed since midnight. - How many full hours and full minutes are passed since midnight? *The program should print two numbers: the number of hours (between 0 and 23) and the number of minutes (between 0 and 1339)*.
In this exercise we are going to suppose that it is midnight, we want that with the function `hours_minutes` that we have provided to you, you were able to tell us how much time has passed since then with the seconds that are introduced as parameter.

## Example:
## 📝 Instructions:

+ If N = 3900 --> then 3900 seconds have passed since midnight - i.e. now it's 1:05am.
1. Complete the function to return the expected result.

+ So the program should print 1 65 --> 1 full hour is passed since midnight, 65 full minutes passed since midnight.
2. Perform two calculations with the seconds that are passed by parameter in the function so that one calculates the time according to the seconds that have passed and the other to know the minutes `(hour , minutes)`.

## Example input:
## Example 1:

```py
hours_minutes(3900)
output = hours_minutes(3900)
print(output) # (1, 5)
```

## Example output:
## Example 2:

+ (1, 65)
```py
output = hours_minutes(60)
print(output) # (0, 1)
```

## 💡 Hints:

+ Remember how many seconds there are in an hour (3600) and how many seconds in a minute (60).

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

+ You may also try step-by-step theory chunks: https://snakify.org/lessons/print_input_numbers/steps/1/


[comment]: <Solution: (secs//3600, secs//60)>
3 changes: 0 additions & 3 deletions exercises/007-hours_and_minutes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ def hours_minutes(secs):

return None




#Invoke the funtion and pass any interger as its argument.
print(hours_minutes(3900))
9 changes: 9 additions & 0 deletions exercises/007-hours_and_minutes/solution.hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Complete the function to calculate how many hours and minutes are passed since midnight.
def hours_minutes(secs):
minutes = secs // 60
hours = minutes // 60
minutes = minutes % 60
return (hours, minutes)

#Invoke the funtion and pass any interger as its argument.
print(hours_minutes(3900))
20 changes: 18 additions & 2 deletions exercises/007-hours_and_minutes/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
@pytest.mark.it('The function hours_minutes must exist')
def test_for_functon_existence(capsys, app):
assert callable(app.hours_minutes)

@pytest.mark.it('The function hours_minutes must return the correct output for 60 secs')
def test_for_file_output(capsys, app):
assert app.hours_minutes(60) == (0, 1)

@pytest.mark.it('The function hours_minutes must return the correct output')
@pytest.mark.it('The function hours_minutes must return the correct output for 3900 secs')
def test_for_file_output(capsys, app):
assert app.hours_minutes(4004) == (4004//3600, 4004//60)
assert app.hours_minutes(3900) == (1, 5)


@pytest.mark.it('The function hours_minutes must return the correct output for 4500 secs')
def test_for_file_output(capsys, app):
assert app.hours_minutes(4500) == (1, 15)


@pytest.mark.it('The function hours_minutes must return the correct output for 7320 secs')
def test_for_file_output(capsys, app):
assert app.hours_minutes(7320) == (2, 2)





Expand Down
3 changes: 3 additions & 0 deletions exercises/29-remove-duplicate-words/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
s = input()
words = [word for word in s.split(" ")]
print (" ".join(sorted(list(set(words)))))
4 changes: 2 additions & 2 deletions exercises/29-remove-duplicate-words/solution.hide.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
s = raw_input()
s = input()
words = [word for word in s.split(" ")]
print " ".join(sorted(list(set(words))))
print (" ".join(sorted(list(set(words)))))
9 changes: 9 additions & 0 deletions exercises/29-remove-duplicate-words/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest, io, sys, json, mock, re, os

@pytest.mark.it('Your solution should work as expected')
def test_expected_output(capsys, app):
fake_input=['Hola como Hola']
with mock.patch('builtins.input', lambda x: fake_input.pop()):
app()
captured = capsys.readouterr()
assert captured.out == " como \n"
2 changes: 1 addition & 1 deletion exercises/38-sort-tuples-ascending/solution.hide.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
break
l.append(tuple(s.split(",")))

print sorted(l, key=itemgetter(0,1,2))
print (sorted(l, key=itemgetter(0,1,2)))
11 changes: 11 additions & 0 deletions exercises/38-sort-tuples-ascending/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest, io, sys, json, mock, re, os
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'

@pytest.mark.it('The solution should return the expected output')
def test_convert_inputs(capsys, app):

fake_input = ["Tom,19,80 John,20,90 Jony,17,91 Jony,17,93 Json,21,85"] #fake input
with mock.patch('builtins.input', lambda x: fake_input.pop()):
app()
captured = capsys.readouterr()
assert captured.out == "[('John', '20', '90'), ('Jony', '17', '91'), ('Jony', '17', '93'), ('Json', '21', '85'), ('Tom', '19', '80')]\n"