Updated the Variable object to reconize 'k' as an installment variable type. Updated the main program's interactive UI.

This commit is contained in:
2020-04-22 02:32:50 -05:00
parent e360323490
commit d43f8ef6be
3 changed files with 35 additions and 18 deletions
+1
View File
@@ -1,2 +1,3 @@
__pycache__
*.json
*.txt
+3 -1
View File
@@ -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):
+31 -17
View File
@@ -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