#说明,我的距离都是负数,所以你们如果是正数需要修改for循环的内容
l1=[100.26,95.46,90.63,85.47,80.91,76.15,71.59,66.88,61.98,57.27,52.61,47.83,43.06,38.24,33.56,28.71] #共振干涉法
l2=[100.14,95.56,90.37,86.08,81.26,76.44,71.8,67.03,62.12,57.56,52.76,48.07,43.28,38.44,33.79,28.87] #相位比较法
l3=[34.71,28.37,22.08,16.92] #时差法
t=[354,372,388,404]
f=[36378,36378,36378,36379,36378] #谐振频率
T=23.4 #室温
######以下内容根据数据修改##########
sum1=0
sum2=0
dL1=[]
dL2=[]
f1=sum(f)/5
vr=331.45+0.59*T
print('Li+8-Li分别为')
for i in range(8):
dL1.append(l1[i]-l1[i+8])
sum1+=l1[i]-l1[i+8]
print(l1[i]-l1[i+8],end=' ')
print('\nLi+8-Li分别为')
for i in range(8):
dL2.append(l2[i]-l2[i+8])
sum2+=l2[i]-l2[i+8]
print(l2[i]-l2[i+8],end=' ')
L1=sum1/8
L2=sum2/8
print('\n△L分别为 '+f'{L1} {L2}')
r1=sum1/32
r2=sum2/32
print('λ分别为 '+f'{r1} {r2}')
v1=f1*r1*0.001
v2=f1*r2*0.001
print('测量声速为 '+f'{v1} {v2}')
E1=(v1-vr)/vr*100
E2=(v2-vr)/vr*100
print("E分别为 "+f'{round(E1,2)}% {round(E2,2)}%')
ufa=(((f[0]-f1)**2+(f[1]-f1)**2+(f[2]-f1)**2+(f[3]-f1)**2+(f[4]-f1)**2)/20)**0.5
ufb=1/(3)**0.5
ufc=((ufa)**2+(ufb)**2)**0.5
ufr=ufc/f1*100
print('频率不确定度a,b,c,r分别为 '+f'{ufa} {ufb} {ufc} {ufr}%')
uLa=(((dL1[0]-L1)**2+(dL1[1]-L1)**2+(dL1[2]-L1)**2+(dL1[3]-L1)**2+(dL1[4]-L1)**2+(dL1[5]-L1)**2+(dL1[6]-L1)**2+(dL1[7]-L1)**2)/56)**0.5
uLb=0.02/(3)**0.5
uLc=((uLa)**2+(uLb)**2)**0.5
uLr=uLc/L1*100
print('共振干涉法△L不确定度a,b,c,r分别为 '+f'{uLa} {uLb} {uLc} {uLr}%')
uvr1=((ufc/f1)**2+(uLc/L1)**2)**0.5*100
uvc1=uvr1*v1/100
uLa=(((dL2[0]-L2)**2+(dL2[1]-L2)**2+(dL2[2]-L2)**2+(dL2[3]-L2)**2+(dL2[4]-L2)**2+(dL2[5]-L2)**2+(dL2[6]-L2)**2+(dL2[7]-L2)**2)/56)**0.5
uLb=0.02/(3)**0.5
uLc=((uLa)**2+(uLb)**2)**0.5
uLr=uLc/L1*100
print('相位比较法△L不确定度a,b,c,r分别为 '+f'{uLa} {uLb} {uLc} {uLr}%')
uvr2=((ufc/f1)**2+(uLc/L2)**2)**0.5*100
uvc2=uvr2*v2/100
print('共振干涉法v不确定度r,c分别为 '+f'{uvr1}% {uvc1}')
print('相位比较法v不确定度r,c分别为 '+f'{uvr2}% {uvc2}')
v3=[]
for i in range(3):
v3.append((l3[i]-l3[i+1])/(t[i+1]-t[i])*1000)
print('时差法测量声速为 '+f'{v3}')
print('平均声速为 '+f'{sum(v3)/3}')
print('相对百分误差为 '+f'{(sum(v3)/3-vr)/vr*100}%')
效果图如下