Improved negative variable handling in the tokenizer. Updated the tolerance checking in the main program.

This commit is contained in:
2020-04-26 19:11:01 -05:00
parent 917b58ee87
commit 5a585cf6f8
2 changed files with 7 additions and 2 deletions
+1 -2
View File
@@ -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):
+6
View File
@@ -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