diff --git a/.gitignore b/.gitignore index 8691330..6722f91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ *.json +*.txt diff --git a/expression.py b/expression.py index 2c25082..67d8f43 100644 --- a/expression.py +++ b/expression.py @@ -19,7 +19,9 @@ class Variable: "i" : "Interest", "I" : "Interest", "n" : "Time", - "N" : "Time" + "N" : "Time", + "k" : "Installment", + "K" : "Installment" } def __init__(self, name, type, starting_point = 0, ending_point = 0): diff --git a/main.py b/main.py index 25993ee..1b931a6 100755 --- a/main.py +++ b/main.py @@ -8,9 +8,10 @@ import itertools import copy base_list = [1, 2, 4, 6, 12] -tolerance = .28 +tolerance = .05 variables = {} + def print_vars(vars): i = 0 for key in vars.keys(): @@ -74,10 +75,21 @@ def modify_variable(var, vars): exp_str = input("Enter the expression the student will use: ") wrong_response = input("Enter the wrong response for the expression: ") + try: wrong_response = float(wrong_response) except ValueError: - print("The anwser must be numeric! Will not be included in output file.") + print("The wrong response must be numeric.") + exit() + +tolerance = input("Enter the tolerance to use: ") + +try: + tolerance = float(tolerance) +except ValueError: + print("The tolerance must be numeric.") + exit() + tokens = tokenizer.get_tokens_from_expression_string(exp_str) rev_tokens = copy.deepcopy(tokens) #rev_tokens.reverse() @@ -88,23 +100,25 @@ for t in rev_tokens: selected_variable = None -while True: - print("Variables in expression:") - print_vars(variables) - response = input("Enter a variable name to modify its properties or continue (default): ") - - if response == "continue" or response == "": - break +if len(variables) > 0: + + while True: + print("Variables in expression:") + print_vars(variables) + response = input("Enter a variable name to modify its properties or continue (default): ") - if response in variables: - selected_variable = variables[response] - - if selected_variable != None: - modify_variable(selected_variable, variables) + if response == "continue" or response == "": + break + + if response in variables: + selected_variable = variables[response] - else: - print("Invalid selection %s." %(response)) - continue + if selected_variable != None: + modify_variable(selected_variable, variables) + + else: + print("Invalid selection %s." %(response)) + continue exp = expression.Expression(exp_str, variables, wrong_response) #exp.variables