進口經營者
定義檢查_等式(eq):
eq = eq.replace(' ','')
match = re.match(r'^(\d+)([\+\-\*\/])(\d+)=(\d+)$',情商)
如果不匹配:
raise ValueError('%s '不是有效的等式。% eq)
op_map = {
+': operator.add,
-’:操作員,
*': operator.mul,
/': operator.floordiv
}
a = int(match.group(1))
op = op_map[match.group(2)]
b = int(match.group(3))
c = int(match.group(4))
return op(a,b) == c
if __name__ == '__main__ ':
eq = input('輸入方程式: ')
打印(檢查等式(eq))