0
私は補間のためにファイルからデータを読み込むコードを書いていましたが、プログラムを実行するときに "pointsx.append(float(words [0])) :Python 'インデックスのリストが間違っています'
with open("points.dat","r") as f:
data = f.readlines()
pointsx = []
pointsy = []
for line in data:
words=(line.split())
pointsx.append(float(words[0]))
pointsy.append(float(words[1]))
x = float(input('Enter the value of X:\n'))
i=0
lenx=len(pointsx)
if x<pointsx[0]:\n
print("this Particular value of X is lower than the range of interpolation \n")
elif x>pointsx[lenx-1]:
print("This particular value of x is higher than the range of interpolation\n")
else:
for i in range(lenx-1):
if(x<=pointsx[i]):
break;
y=pointsy[i-1]+((pointsy[i]-pointsy[i-1])/(pointsx[i]-pointsx[i-1]))*(x-pointsx[i-1])
print("The required value of y is ",y,"\n")
f.close()
があります。。。あなたのファイルにemが含まれているとpty行ですか? (終わりでさえ) –
ohhたくさんありがとう。最後に空白行がありました。今解決されました。 :) –