def validator(self, user_answer): try: 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 has_letters(user_answer): if '<' in user_answer or '>' in user_answer: print('great!') elif '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 += latex(ans) + ' ,' format_answer = format_answer[:-2] except: raise SyntaxError
def checkanswer(self, user_answer): user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') if has_letters(user_answer): if 'x' not in user_answer: return False else: user_answer = user_answer.replace('x', '') user_answer = user_answer.replace('=', '') user_answer = user_answer.replace(',', '') user_answers = user_answer.split('or') else: user_answers = user_answer.split(',') user_answers = [ parse_expr(ans, transformations=transformations) for ans in user_answers ] user_answers = set(user_answers) return self.answer == user_answers
def format_useranswer(self, user_answer, display=False): user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') if has_letters(user_answer): if 'x' not in user_answer: return user_answer else: user_answer = user_answer.replace('x', '') user_answer = user_answer.replace('=', '') user_answer = user_answer.replace(',', '') user_answers = user_answer.split('or') user_answers = [ parse_expr(ans, transformations=transformations) for ans in user_answers ] out = '' for ans in user_answers: out += latex(ans) + ', ' out = out[:-2] return f'\\({out}\\)' else: return f'\\({user_answer}\\)'
def validator(self, user_answer): try: # pass user_answer = user_answer.lower() user_answer = user_answer.replace('^', '**') if has_letters(user_answer): if 'x' not in user_answer: raise SyntaxError elif ',' in user_answer and 'or' not in user_answer: raise SyntaxError else: user_answer = user_answer.replace('x', '') user_answer = user_answer.replace('=', '') user_answer = user_answer.replace(',', '') user_answers = user_answer.split('or') else: user_answers = user_answer.split(',') user_answers = [ parse_expr(ans, transformations=transformations) for ans in user_answers ] user_answers = set(user_answers) except: raise SyntaxError
def format_useranswer(self, user_answer, display=False): # user_answer = user_answer.lower() if has_letters(user_answer): return user_answer else: return f'\({user_answer}\)'