溶解曲线程序
def merge(left, right):
result = []
i = 0
j = 0
while (len(left) > i and len(right) > j):
if left[i] > right[j]:
# print("i, j: %d %d" % (i, j))
result.append(right[j])
j = j + 1
el:
result.append(left[i])
i = i + 1
ps背景填充
# print("left: %d %d" % ( len(left), i))
# print("right: %d %d" % ( len(right), j))
result += left[i:]
result += right[j:]
伏羲庙 return result
def sort(alist):
if len(alist) < 2:
return alist
el:
mid = len(alist) // 2
left = sort(alist[:mid])
right = sort(alist[mid:])
return merge(left, right)
filename = input("Plea input filename: ")
try:
fd = open(filename, "r")最美的姿态
lst = fd.readlines()
fd.clo()
except IOError as e:
print("I/O Error({0}): {1}"., e.strerror))
exit()
"""
以上,设定的是读取文件的过程,并使用split分割字符串儿童鱼肝油
将每一行解析为两个元素,一个是温度,另一个是影响因子
"""
lstdata = [] # 元素是浓度
lsttemp = [] # 元素是温度
for ele in lst:
lsttup = ele.split()
# lst = ['318 0.460', '332 0.427', '341 0.403']
园林造景>三省吾身是什么意思
# lsttup = [('318', '0.460'), ('332', '0.427'), ('341', '0.403')]
# lsttemp = [318, 332, 341]
# lstdata = [0.460, 0.427, 0.403]
lsttemp.append(float(lsttup[0])) # 将字符型转化为数字型,获得温度量
lstdata.append(float(lsttup[1])) # 将字符型转化为数字型,获得溶解量
temp = sort(lsttemp) # 将温度量从小到大排序
dens = [] # 定义一个密度的列表
for ele in temp:
# 下面,使用ele 和 lsttemp 将温度量和对应的溶解量找出来
for i in range(len(lsttemp)):
if ele == lsttemp[i]:
dens.append(lstdata[i])
# 下面,把温度和密度都写入新的文件中
fd = open(filename+"_r", "w")
fd.write("Temperature Density\n")
fd.write("---------- -------\n")
i = 0
while(i < len(temp) - 1):
tl = '{:>10.2f} {:>7.3f}\n'.format(temp[i], dens[i])
汽车行业现状 fd.write(tl)
i = i + 1
tl = '{:>10.2f} {:>7.3f}'.format(temp[i], dens[i])
fd.write(tl)
fd.clo()
print("%s_r is generated sucessfully!" % filename)
羊八井