newer_project / modules /calculator.py
YaTharThShaRma999's picture
Update modules/calculator.py
afeb835 verified
raw
history blame
No virus
569 Bytes
import math
def math_solver(expression):
"simple math equation solver, supports powers, square root, addition, subtraction, multiplication and division. honestly pretty easy to implement."
expression = expression.replace('x', '*')
expression = expression.replace("^", "**")
try:
result = eval(expression, {'__builtins__': None}, {'sqrt': math.sqrt, 'sin': math.sin, 'cos': math.cos, 'tan': math.tan, 'log': math.log})
except Exception as e:
result = str(e)
return {"llm_output": str(result), "real_output": None, "type": "text"}