首页 > 代码库 > 表达式计算(re运用)

表达式计算(re运用)

import re
ex=raw_input()
num="1234567890"
a=re.findall("\d+",ex)
b=re.findall("[+-]",ex)
l=[]
if len(a)==len(b):
    for i in range(len(a)):
        l.append(int(b[i]+a[i]))
else:#a=b+1
    l.append(int(a[0]))
    for i in range(1,len(a)):
        l.append(int(b[i-1]+a[i]))
    
print sum(l)