I have a data file named st and it contains many lines of variables and each line of them has the specific name. I want to select two specific lines of those data with names and assigned them to values. My codes are as bellow and it just selects one line of my data and ignores the second 'if' condition. Does anybody have an Idea?
with open(input("ENTER YOUR STATIONS COORDINATES FILE NAME : "), 'r') as st:
ST = input("ENTER YOUR STATION NAME :").upper()
ST1 = input("ENTER YOUR 00 STATION NAME :").upper()
with open(input("ENTER YOUR COORDINATE FILE NAME :"), 'r') as f1:
with open(input("ENTER YOUR OUTPUT FILE NAME :"), 'w') as f2:
print(ST, ST1)
for lines in st:
values = lines.split()
NO = int(values[0])
X = float(values[1])
Y = float(values[2])
Z = float(values[3])
Code = values[4]
if Code == ST:
X1 = float(values[1])
Y1 = float(values[2])
print(X1, Y1)
if Code == ST1:
X00 = float(values[1])
Y00 = float(values[2])
print(X1, Y1, X00, Y00)
st.close()
A part of My input data:
1 1505.114 5528.524 1060.572 S1
2 1283.787 5442.505 1084.851 S3
3 1189.962 5272.845 1108.214 S3t1
My code output as is below:
ENTER YOUR STATIONS COORDINATES FILE NAME: st
ENTER YOUR STATION NAME:s3t2
ENTER YOUR 00 STATION NAME:s3
ENTER YOUR COORDINATE FILE NAME:h.dat
ENTER YOUR OUTPUT FILE NAME:h.out
S3T2 S3
1059.056 5230.141
Process finished with exit code 0*
Aucun commentaire:
Enregistrer un commentaire