This python code is not solving equations
<p>I have a chat bot for an Instant messenger and I am trying to make a math solver for it but it can't send the solution of equation to the Instant messenger, it sends equation instead.</p>

<p>If someone from Instant messenger sends "solve: 2+2", this program should send them "4" not "2+2".</p>

<p><strong>Main problem:</strong></p>

<pre><code>if (parser.getPayload().lower()[:6]=="solve:"):
                    parser.sendGroupMessage(parser.getTargetID(), str(parser.getPayload()[7:]))
</code></pre>

<p><strong>output:</strong></p>

<p><a href="http://i.stack.imgur.com/Rf4ND.png" rel="nofollow">it's sending same input again not the answer of equation</a></p>

<p><strong>Test:</strong>
I tested something and that's working properly. If I add this code, program will send solution of equation:</p>

<pre><code>if (parser.getPayload().lower()=="test"):
                    parser.sendGroupMessage(parser.getTargetID(), str(2 + 2 -3 + 8 * 7))
</code></pre>

<p><strong>Output:</strong>
<a href="http://i.stack.imgur.com/uHg55.png" rel="nofollow">Working perfectly</a></p>

<p>What you need to do this evaluating math expressions in string form.</p>

<p>However, user inputs are dangerous if you are just <code>eval</code> things whatever they give you. <a href="http://stackoverflow.com/questions/661084/security-of-pythons-eval-on-untrusted-strings">Security of Python&#39;s eval() on untrusted strings?</a></p>

<p>You can use <code>ast.literal_eval</code> to lower the risk.</p>

<p>Or you can use a evaluator from answers of following question
<a href="http://stackoverflow.com/questions/2371436/evaluating-a-mathematical-expression-in-a-string">Evaluating a mathematical expression in a string</a></p>

python bots irc instant-messaging payload