diff --git a/main.py b/main.py index d123f96..3cc1799 100755 --- a/main.py +++ b/main.py @@ -169,8 +169,7 @@ for r in res: t = tokenizer.replace_variables(tokens, list(r)) #tokenizer.print_token_list(t) result = calc_engine.calculate_results(t) - tol = int(exp.wrong_response * tolerance + exp.wrong_response) - if result <= tol and result >= int(exp.wrong_response - exp.wrong_response * tolerance): + if result <= int(exp.wrong_response(1 + tolerance)) and result >= int(exp.wrong_response(1 - tolerance)): if not result in answers: answers[result] = t #if result <= tol and result >= int(exp.wrong_response - exp.wrong_response * tolerance): diff --git a/tokenizer.py b/tokenizer.py index 774ff31..ca4c4bf 100644 --- a/tokenizer.py +++ b/tokenizer.py @@ -44,6 +44,12 @@ def get_tokens_from_expression_string(expression_string): #Must be a variable. if tokens[-1].type == token.TokenType.exp_start: variable_is_negative = True + elif token.TokenType.get_operator(tokens[-1].value) != token.TokenType.unknown: + variable_is_negative = True + elif tokens[-1].type == token.TokenType.exp_end: + tokens.append(token.Token(c, token.TokenType.get_operator(c))) + parsing_number = False + tmp = "" else: tokens.append(token.Token(c, token.TokenType.get_operator(c))) parsing_number = False