Updated the Variable object to reconize 'k' as an installment variable type. Updated the main program's interactive UI.
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
*.json
|
*.json
|
||||||
|
*.txt
|
||||||
|
|||||||
+3
-1
@@ -19,7 +19,9 @@ class Variable:
|
|||||||
"i" : "Interest",
|
"i" : "Interest",
|
||||||
"I" : "Interest",
|
"I" : "Interest",
|
||||||
"n" : "Time",
|
"n" : "Time",
|
||||||
"N" : "Time"
|
"N" : "Time",
|
||||||
|
"k" : "Installment",
|
||||||
|
"K" : "Installment"
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, name, type, starting_point = 0, ending_point = 0):
|
def __init__(self, name, type, starting_point = 0, ending_point = 0):
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ import itertools
|
|||||||
import copy
|
import copy
|
||||||
|
|
||||||
base_list = [1, 2, 4, 6, 12]
|
base_list = [1, 2, 4, 6, 12]
|
||||||
tolerance = .28
|
tolerance = .05
|
||||||
|
|
||||||
variables = {}
|
variables = {}
|
||||||
|
|
||||||
def print_vars(vars):
|
def print_vars(vars):
|
||||||
i = 0
|
i = 0
|
||||||
for key in vars.keys():
|
for key in vars.keys():
|
||||||
@@ -74,10 +75,21 @@ def modify_variable(var, vars):
|
|||||||
|
|
||||||
exp_str = input("Enter the expression the student will use: ")
|
exp_str = input("Enter the expression the student will use: ")
|
||||||
wrong_response = input("Enter the wrong response for the expression: ")
|
wrong_response = input("Enter the wrong response for the expression: ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
wrong_response = float(wrong_response)
|
wrong_response = float(wrong_response)
|
||||||
except ValueError:
|
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)
|
tokens = tokenizer.get_tokens_from_expression_string(exp_str)
|
||||||
rev_tokens = copy.deepcopy(tokens)
|
rev_tokens = copy.deepcopy(tokens)
|
||||||
#rev_tokens.reverse()
|
#rev_tokens.reverse()
|
||||||
@@ -88,23 +100,25 @@ for t in rev_tokens:
|
|||||||
|
|
||||||
selected_variable = None
|
selected_variable = None
|
||||||
|
|
||||||
while True:
|
if len(variables) > 0:
|
||||||
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 == "":
|
while True:
|
||||||
break
|
print("Variables in expression:")
|
||||||
|
print_vars(variables)
|
||||||
|
response = input("Enter a variable name to modify its properties or continue (default): ")
|
||||||
|
|
||||||
if response in variables:
|
if response == "continue" or response == "":
|
||||||
selected_variable = variables[response]
|
break
|
||||||
|
|
||||||
if selected_variable != None:
|
if response in variables:
|
||||||
modify_variable(selected_variable, variables)
|
selected_variable = variables[response]
|
||||||
|
|
||||||
else:
|
if selected_variable != None:
|
||||||
print("Invalid selection %s." %(response))
|
modify_variable(selected_variable, variables)
|
||||||
continue
|
|
||||||
|
else:
|
||||||
|
print("Invalid selection %s." %(response))
|
||||||
|
continue
|
||||||
|
|
||||||
exp = expression.Expression(exp_str, variables, wrong_response)
|
exp = expression.Expression(exp_str, variables, wrong_response)
|
||||||
#exp.variables
|
#exp.variables
|
||||||
|
|||||||
Reference in New Issue
Block a user