I've a problem that i didn't understand . I'm trying to learn my robot to count; If i ask him "compute 2+3" he say "5", but if i ask him to compute 2 X 5, he can't, of course, he wait for 2*5 instead of 2X5 .
So this is my function in python :
def math(text): print type(text) if isinstance(text, basestring): text.lower() print "string" text.replace('x','*') text = eval(text) print text
for "2+3" math() recept automaticly "5" , python apply eval() automaticly when it receive a message from programAB ?
for "2 x 5 " , i get this error :
SyntaxError: ("no viable alternative at input 'x'", ('<string>', 1, 7, 'math(2 x 5)\n'))
This error appear before execute the first line in the function . I tryed this to get the type of data received to be sure it's a string, but it dosen't worked :(
if someone have an idea ! :D
This is the category used in my .aiml file :
<category><pattern>COMPUTE *</pattern> <template> <oob> <mrl> <service>python</service> <method>exec</method> <param>math(<star/>)</param> </mrl> </oob> </template> </category>
Thx for your help