def checkanswer(self, user_answer): user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') user_answer = parse_expr(user_answer, transformations=transformations) answer = simplify_for_long_division(self.answer) user_answer = simplify_for_long_division(user_answer) return answer == user_answer
def validator(user_answer): try: user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') user_answer = parse_expr(user_answer, transformations=transformations) user_answer = simplify_for_long_division(user_answer) except: raise SyntaxError
def format_useranswer(user_answer, display=False): user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') user_answer = parse_expr(user_answer, transformations=transformations) user_answer = simplify_for_long_division(user_answer) return f'\({sy.latex(user_answer)}\)'