<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query_cast(value, answers, ignorecase = False):
 """A cast function for query Answers should look something like it does in query """

    if ignorecase: value = value.lower()
    for item in answers:
        for a in item['values']:
            if ignorecase and (value == str(a).lower()):
                return item['values'][0]
            elif value == a:
                return item['values'][0]
    raise ValueError("Response '%s' not understood, please try again." % value)