Esempio n. 1
0
 def format_useranswer(self, user_answer, display=False):
     user_answer = user_answer.split(' ')
     for i in range(len(user_answer)):
         word = user_answer[i]
         try:
             if has_numbers(word):
                 word = word.replace('^', '**')
                 word = parse_expr(word, transformations=transformations)
                 user_answer[i] = latex(word)
         except:
             pass
     formatted = ''
     for word in user_answer:
         formatted += str(word) + ' '
     return formatted
 def validator(self, user_answer):
     try:
         # pass
         user_answer = user_answer.lower()
         user_answer = user_answer.replace('x', ' ')
         user_answer = user_answer.replace('=', ' ')
         user_answer = user_answer.replace('^', '**')
         user_answer = user_answer.replace('or', ',')
         if not has_numbers(user_answer):
             if 'no' not in user_answer and 'null' not in user_answer and 'empty' not in user_answer:
                 raise SyntaxError
         user_answers = user_answer.split(',')
         i = 0
         while i < len(user_answers):
             user_answers[i] = parse_expr(user_answers[i], transformations=transformations)
             i += 1
         user_answers = set(user_answers)
         format_answer = ''
         for ans in user_answers:
             format_answer += sy.latex(ans) + ' ,'
         format_answer = format_answer[:-2]
     except:
         raise SyntaxError