-1
I want to write a Python function, called separates, that takes a Tuplo whose elements are pairs (double 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 shall return 1 tuple with two elements:
- 1 Double with the elements of the original Double in which the age is less than 18.
- 1 Double section with the elements of the original Double section where the age is 18 or over.
- Your function should check that the received argument is correct (use exercise 1 function to do this check). If the argument is not correct an error must be generated, with the raise statement Valueerror('separates: incorrect argument. ').
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.
What did you try? Apart from copying the question statement, you had some difficulty?
– fernandosavio
And now, with you, Celso Overflow from "Pass Glue and Answer Soon".
– nmindz
I’m not realizing how I can do it.
– crocs
Sousa, please, Sopt works best when the questions are more general and apply broadly to the site’s audience. In other words, "how to solve an exercise" is not a good question. Neither is copying the statement. There needs to be more engagement on your part in explaining, formatting, and demonstrating the problem. tried do. Summarize your doubts, do questions. Read that and this to try to fit your question.
– nmindz
This is what I did: def verifies(variable): if isinstance(variable, tuple): if isinstance(variable[0], str) and isinstance(variable[1], int): Return True Else: Return False Else: Return False Turn
– crocs
@Please click on [Edit] and add the code to the question. Thus it is more organized (other users do not need to "hunt" information in the comments, all relevant information is in the question), and in addition it is more readable, because it is possible to format the code (see here tips on how to format). This is even more important in Python, since indentation is part of the syntax, and in the comments it is not clear how indentation is
– hkotsubo
Possible duplicate of How to validate if a value is a tuple having a string and an integer?
– crocs