How to implement the division sentence in python?

For example, I write in the console: "Divide 8 by 4", and the program performs this division.
I dokumekal that the word "stripped" can be found using "find", but I don't know what then need to put numbers into variables? Please help
June 10th 19 at 16:17
1 answer
June 10th 19 at 16:19
Solution
>>> ops = {u"stripped":"/", u"multiply":"*", u"put": "+"}
>>> import re
>>> seeking = re.compile(r"(.*)\s+(\d+)\s+.*(\d+)")
>>> def my_eval(in_oper):
... res = seeking.match(in_oper)
... if res:
... my_op = ops.get(res.group(1).lower(), None)
... if my_op:
... return eval('{}{}{}'.format(res.group(2), my_op, res.group(3)))
...
>>> print my_eval(u"Divide 8 by 4")
2
>>> print my_eval(u"Multiply 3 by 4")
12
>>> print my_eval(u"Fold 3 and 4")
7
You have somebody called a genius? If not, I will call, "You're a genius!". Thank you. - rita_Towne commented on June 10th 19 at 16:22

Find more questions by tags Python