Commit c79843c5 by Sarina Canelake

Add factorial as a default function for formula response

parent 72dfd499
...@@ -24,7 +24,9 @@ default_functions = {'sin': numpy.sin, ...@@ -24,7 +24,9 @@ default_functions = {'sin': numpy.sin,
'arccos': numpy.arccos, 'arccos': numpy.arccos,
'arcsin': numpy.arcsin, 'arcsin': numpy.arcsin,
'arctan': numpy.arctan, 'arctan': numpy.arctan,
'abs': numpy.abs 'abs': numpy.abs,
'fact': math.factorial,
'factorial': math.factorial
} }
default_variables = {'j': numpy.complex(0, 1), default_variables = {'j': numpy.complex(0, 1),
'e': numpy.e, 'e': numpy.e,
...@@ -246,4 +248,9 @@ if __name__ == '__main__': ...@@ -246,4 +248,9 @@ if __name__ == '__main__':
print evaluator({}, {}, "5+1*j") print evaluator({}, {}, "5+1*j")
print evaluator({}, {}, "j||1") print evaluator({}, {}, "j||1")
print evaluator({}, {}, "e^(j*pi)") print evaluator({}, {}, "e^(j*pi)")
print evaluator({}, {}, "fact(5)")
print evaluator({}, {}, "factorial(5)")
try:
print evaluator({}, {}, "5+7 QWSEKO") print evaluator({}, {}, "5+7 QWSEKO")
except UndefinedVariable:
print "Successfully caught undefined variable"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment