私はPythonを初めて使用するので、ここに問題があります。31行目のy_listの最初のifの後に、「IndentationError:インデントされたブロックが必要です」というエラーが表示されます。私がロードするファイルにはたくさんの数字が含まれており、そのアイデアはいわゆる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