我收到“列表索引超出范围”。我想我错误地命名了其中一个变量。如果我把剩下的加进去可能更有意义。
我正在尝试打印出列表中坐标的差异。我确定它搞砸了str(distance_list[i])
。
相关代码:
# Get the maximum distance from the user
maxDistance = float(raw_input("What is the maximum distance from the base?"))
# Set the base N,E values
#baseEasting = float(raw_input("What is the easting of the base?"))
#baseNorthing = float(raw_input("What is the northing of the base?"))
baseEasting = "346607"
baseNorthing="6274191"
#TODO: Place the values for meterological stations into the lists
stationCoords = [ [476050, 7709929],[473971,7707713],[465676,7691097] ,[515612,7702192] ,[516655,7704405],[519788,7713255],[538466,7683341] ]
numCoords = len(stationCoords)
distance_list = []
for i in range (0, numCoords):
stationNorthing=stationCoords[i][0]
stationEasting=stationCoords[i][1]
distance = calculateDistance(stationNorthing, stationEasting, EASTING_BASE, NORTHING_BASE)
if distance <= maxDistance:
# Calculate output string
strTextOut = "Co-ordinates: " + str(distance_list[i])
+ ", at: " + str(round(distance, 0)) + " m"
# Output the string
print(strTextOut)
希望这就是相关的一切。但是 stationCoords 中已经有值了。