Challenge: Type Validation Decorator
Tarefa
Swipe to start coding
Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.
- Define the
int_validatedecorator that takes afunc(function) as an argument. - Inside
int_validate(), define awrapperfunction that takes a varying number of arguments. - For each argument, check if its type is
int. If the type is not int, raise aTypeErrorwith the message"The function expects the integer type". - Call the
func()with the arguments taken bywrapper(), and return its result (don't forget to unpack the arguments). - The
int_validate()decorator should return thewrapperfunction without calling it. - Decorate the
int_sum()function using theint_validatedecorator.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 4
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Suggested prompts:
Resumir este capítulo
Explicar o código em file
Explicar por que file não resolve a tarefa
Awesome!
Completion rate improved to 6.67
Challenge: Type Validation Decorator
Deslize para mostrar o menu
Tarefa
Swipe to start coding
Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.
- Define the
int_validatedecorator that takes afunc(function) as an argument. - Inside
int_validate(), define awrapperfunction that takes a varying number of arguments. - For each argument, check if its type is
int. If the type is not int, raise aTypeErrorwith the message"The function expects the integer type". - Call the
func()with the arguments taken bywrapper(), and return its result (don't forget to unpack the arguments). - The
int_validate()decorator should return thewrapperfunction without calling it. - Decorate the
int_sum()function using theint_validatedecorator.
Solução
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 4
single