I want to write a function in Python, call separates, which receives a tuple tup whose elements are pairs (double of 2 elements), where the 1st element is a name (a string) and the 2nd element is an age (an integer), as described in the previous exercise.
The function should return 1 tuple with two elements:
- 1 tuple with the elements of the original tuple where the age is less than 18.
- 1 tuple with the elements of the original tuple where the age is greater than or equal to 18.
- Your function should check if the argument you received is correct (use exercise 1 function to do this check). If the argument is not correct, an error should be generated with the raise statement ValueError ('separa: argument incorrect.').
Example:
>>> tup = (('Maria', 38), ('Miguel', 17), ('Tiago', 18), ('Sara', 19))
>>> menores, maiores = separa(tup)
>>> menores
(('Miguel', 17),)
>>> maiores
(('Maria', 38), ('Tiago', 18), ('Sara', 19))
>>> separa(())
((), ())
>>> separa((('Maria', 38), ('Miguel', 17), ('Tiago', 18), ('Sara', 19.7)))
….
builtins.ValueError: separa: argumento incorrecto.