Wrote some more comments about the code.
This commit is contained in:
+12
-4
@@ -1,8 +1,10 @@
|
||||
class Expression:
|
||||
expression = ""
|
||||
# This object represents all the needed initial data about an expression that is to be parsed.
|
||||
|
||||
expression = "" # The formula to parse as a string.
|
||||
# correct_response = 0
|
||||
wrong_response = 0
|
||||
variables = []
|
||||
wrong_response = 0 # The incorrect response that was entered by the student.
|
||||
variables = [] # A list of Variable.
|
||||
|
||||
def __init__(self, expression_string, variables, wrong_response):
|
||||
self.expression = expression_string
|
||||
@@ -10,10 +12,13 @@ class Expression:
|
||||
self.wrong_response = wrong_response
|
||||
|
||||
class Variable:
|
||||
# This object represents a variable that is found in the formula. It encodes the name, the type of variable
|
||||
# and the starting point from which to look for mutations in the variable's value.
|
||||
|
||||
name = ""
|
||||
type = ""
|
||||
starting_point = 0
|
||||
ending_point = 0
|
||||
# ending_point = 0
|
||||
|
||||
VARIABLE_TYPES = {
|
||||
"i" : "Interest",
|
||||
@@ -32,6 +37,9 @@ class Variable:
|
||||
|
||||
@staticmethod
|
||||
def get_variable_type(variable_name):
|
||||
# Utilitie function to get the variable's type from it's name.
|
||||
# For example, a variable with 'i' in its name is an Interest type.
|
||||
# Returns the variable's type as a string or 'Unknown' otherwise.
|
||||
if not variable_name in Variable.VARIABLE_TYPES:
|
||||
return "Unknown"
|
||||
return Variable.VARIABLE_TYPES[variable_name]
|
||||
|
||||
@@ -3,7 +3,7 @@ import tokenizer
|
||||
import expression
|
||||
import calc_engine
|
||||
import factors
|
||||
import jsonpickle
|
||||
#import jsonpickle
|
||||
import itertools
|
||||
import copy
|
||||
|
||||
@@ -14,6 +14,8 @@ variables = {}
|
||||
var_types = {}
|
||||
|
||||
def print_vars(vars):
|
||||
# Utility function to print out the variables list to standard out.
|
||||
|
||||
i = 0
|
||||
for key in vars.keys():
|
||||
var = vars[key]
|
||||
@@ -25,6 +27,8 @@ def print_vars(vars):
|
||||
print()
|
||||
|
||||
def modify_variable(var, vars):
|
||||
# Acts as an interactive prompt that allows the user to modify any one variable that has been found in the formula string.
|
||||
|
||||
print("%s is now selected." %(var.name))
|
||||
print("The following properties are avaliable: Variable Type, Starting Point and Ending Point.")
|
||||
print('Commands are "type", "start" and "end", respectly.')
|
||||
|
||||
Reference in New Issue
Block a user