1
只是詢問是否有可能的代碼或方法來計算文本文件中的整行。 例如,我有以下文本文件;如何從文本文件中計算一行?
Force Displacement Theta
0 0 0
15 0 0
3 0.15 0
1 1 90
-3 0.15 0
我想用它來計算由線這些數字線WorkDone
W =力×位移* COS
我已經試過(西塔);
fname = input("Please enter the filename: ")
infile = open(fname, "r")
with open(fname, 'r'):
data = infile.readline()
f,D,Theta = eval(data)
display = f * D * cos(radians(Theta))
output.setText(("%,2f") % display)
我不知道我這樣做了,請幫助
循環在哪裏?您只獲取文件的第一行。 – dede
不要擔心這一點。我只想知道是否有可能的代碼來做到這一點。 – Donkey
你的意思是:計算輸入文本文件每一行的結果? – xtofl