name=input('请输入表达式')shu=[]fu=[]expre=''forxinname:ifx=='':continueelifx!='':expre=expre+xforxinexpre:ifx=='+':fu.append(x)elifx=='*':fu.append(x)elifx=='-':fu.appen...
name=input('请输入表达式')
shu=[]
fu=[]
expre=''
for x in name:
if x==' ':
continue
elif x!=' ':
expre=expre+x
for x in expre:
if x=='+':
fu.append(x)
elif x=='*':
fu.append(x)
elif x=='-':
fu.append(x)
elif x=='/':
fu.append(x)
else:
x=int(x)
shu.append(x);
print(shu)
for x in range(len(fu)):
if fu[x]=='*':
shu[x+1]=shu[x]*shu[x+1]
shu[x]=0
elif fu[x]=='/':
shu[x + 1] = shu[x] * shu[x + 1]
shu[x] = 0
elif fu[x]=='-':
shu[x+1]=-shu[x+1]
else:
continue
s=int(0)
for x in range(len(shu)):
s=s+shu[x]
print(shu)
print(s)
上面是我写的源代码,该怎么去处理多位数的数字啊?想了好多方法都没弄出来(刚学没多久)
展开