利用正则实现计算器 利用正则来实现简单计算器的功能,能够设计计算带括号的加减乘除运算.当然不使用eval等语句. 利用递归: import re from functools import reduce def foo2(y): if '(' in y: t1 = re.search(r'\([^()]+\)',y) temp1 = t1.group().strip('()') res = foo1(temp1) y = y.replace(t1.group(),str(res)) return…
经过2天的长时间的战斗,python计算器终于完成了. import re val="1-2*((60-30*(9-2*5/3+7/3*99/4*2998+10*568/14))-(-4*3)/(16-3*2))" def chen(arg): f = arg # print (f) if "*" in arg or "/" in arg: '''如果包含*号或者除好则进如该方法''' b2_2 = re.search("\d+\.?\…