Changed the JSON generator to generate JSON that includes the correct answer for the expression.
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"expression": "i + 2 + n",
|
||||
"variables": {
|
||||
"n1": {
|
||||
"name": "n1",
|
||||
"type": "Unknown",
|
||||
"starting_point": 0,
|
||||
"ending_point": 0
|
||||
},
|
||||
"i1": {
|
||||
"name": "i1",
|
||||
"type": "Unknown",
|
||||
"starting_point": 0,
|
||||
"ending_point": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
class Expression:
|
||||
expression = ""
|
||||
correct_answer = 0
|
||||
variables = []
|
||||
|
||||
def __init__(self, expression_string, variables):
|
||||
def __init__(self, expression_string, variables, correct):
|
||||
self.expression = expression_string
|
||||
self.variables = variables
|
||||
self.correct_answer = correct
|
||||
|
||||
class Variable:
|
||||
VARIABLE_TYPES = {
|
||||
|
||||
@@ -66,6 +66,11 @@ def transform(object):
|
||||
raise TypeError("Only Books and Index will be JSON serialized!")
|
||||
|
||||
exp = input("Enter the expression the student will use: ")
|
||||
correct_answer = input("Enter the correct anwser for the expression: ")
|
||||
try:
|
||||
correct_answer = float(correct_answer)
|
||||
except ValueError:
|
||||
print("The anwser must be numeric! Will not be included in output file.")
|
||||
tokens = tokenizer.get_tokens_from_expression_string(exp)
|
||||
|
||||
for t in tokens:
|
||||
@@ -92,5 +97,5 @@ while True:
|
||||
print("Invalid selection %s." %(response))
|
||||
continue
|
||||
|
||||
with open("data.json", "w", encoding="utf-8") as f:
|
||||
json.dump(expression.Expression(exp, variables), f, default=transform, indent = 4)
|
||||
with open("expression.json", "w", encoding="utf-8") as f:
|
||||
json.dump(expression.Expression(exp, variables, correct_answer), f, default=transform, indent = 4)
|
||||
|
||||
Reference in New Issue
Block a user