我是python新手,所以这是我的问题。我在第 31 行的 y_list 上收到错误“IndentationError: expected an indented block” -> 在第一个 if 之后。我加载的文件包含很多数字,我们的想法是跳过所谓的 y_list 中的负数。
filename = "data_5.dat" # this file can also be found in the sandbox folder
x_list = []
y_list = []
fp = open(filename)
for line in fp:
var1, var2 = line.split(",") # here we wish to split the line using the ',' character
# since we want them in numeric format we need to convert
a = float(var1)
b = float(var2)
# put them into two lists
x_list.append(a)
y_list.append(b)
fp.close() # close the file
x = x_list
y = y_list
I = 0.0
L = 0.0
for k in range(1, len(x)):
if y_list>0:
y_list.append(y)
I += y[k-1] * (x[k] - x[k-1])
for k in range(1, len(x)):
if y_list>0:
y_list.append(y)
L += y[k] * (x[k] - x[k-1])
print I
print L
print (I+L)/2