From babbdc20afc8a47948052668dbae72a211bbb7b5 Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Wed, 29 Apr 2020 22:13:34 -0500 Subject: [PATCH] Wrote some more comments about the code. --- expression.py | 16 ++++++++++++---- main.py | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/expression.py b/expression.py index 67d8f43..8e04869 100644 --- a/expression.py +++ b/expression.py @@ -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] diff --git a/main.py b/main.py index 3cc1799..2cdc997 100755 --- a/main.py +++ b/main.py @@ -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.')