团队-象棋游戏-模块开发过程

def calculate(expression):
ex=[]
ans=0
if '(' not in expression:
ans=fun(expression)
return ans
for i in range(len(expression)):
if expression[i]=='(':
ex.append(i) 
elif expression[i]==')': 
temp=0
sub=expression[ex[len(ex)-1]+1:i]
temp=fun(sub)
expression=expression[0:ex[len(ex)-1]]+str(temp)+expression[i+1:len(expression)+1]
ex.pop()
return calculate(expression)

s='1 - 2 * ( (60-30 +(-40/5+3) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) )'

print(1 - 2 * ( (60-30 +(-40/5+3) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) ))
s3='3*(4+50)-((100+40)*5/2-3*2*2/4+9)*(((3+4)-4)-4)'                
print(3*(4+50)-((100+40)*5/2-3*2*2/4+9)*(((3+4)-4)-4))
print(calculate(s))                                                
print(calculate(s3))

posted on 2017-11-03 11:26  杨温柔1  阅读(155)  评论(0编辑  收藏  举报