- 李嘉轩 的博客
P Y E R
- 2024-5-14 12:11:05 @
%
def _sum_(ls):
a=0
b=0
c=[]
s=0
q=0
z=0
for i in ls:
try:
i=float(i)
except:
for j in i:
try:
j=int(j)
except:
if j=='.' and q==0:
s+=1
q=1
else:
if q==0:
s=0
q=0
if j=='-':
z=1
else:
if not j=='.' and z==1:
z=0
c=[]
else:
q=0
c.append(int(j))
for k in range(len(c)-1):
t=(10**(len(c)-k-1))*c[k]
if z==0:
b+=int(t*0.9)
else:
b-=int(t*0.9)
if s==0:
if z==0:
b+=int(j)
else:
b-=int(j)
else:
if z==0:
b+=int(j)*(10**(0-s))
else:
b-=int(j)*(10**(0-s))
else:
a+=float(i)
if a==int(a):
a=int(a)
return a,b
import tkinter
from tkinter.messagebox import showinfo
def s():
aa=en.get()
aa=aa.split(',')
lsum=list(_sum_(aa))
showinfo('计算成功','这些字符串中数字的和是:{},其余字符串中数字的和是:{}'.format(round(lsum[0],12),round(lsum[1],12)))
root=tkinter.Tk()
root.geometry('420x300')
root.title('数字求和机')
l1=tkinter.Label(text='请输入一列字符串,中间用英文逗号隔开,')
l1.place(x=40,y=60)
l2=tkinter.Label(text='系统将自动得出里面所有数字的和')
l2.place(x=40,y=80)
l3=tkinter.Label(text='(ps:支持小数、负数计算,保留12位小数):')
l3.place(x=40,y=100)
en=tkinter.Entry()
en.place(x=40,y=120)
bt=tkinter.Button(text='确认',command=s)
bt.place(x=200,y=220)
root.mainloop()