Sample data (towers1.txt
):
MS33 42.19 -70.33 3.6
JS89 42.23 -70.30 3.9
ED22 42.25 -70.33 3.4
HE90 42.27 -70.35 3.7
TW05 42.30 -70.30 3.4
WW23 42.37 -70.28 3.7
Code:
lr = []
import lat_long_to_dist
f = open('towers1.txt','r')
towers = [line.strip('\n') for line in f]
for line in towers:
lr.append(line.split())
I'm trying to figure out how to use 2 for loops only (I have not learned dictionaries and above) to have the first for loop for the Towers themselves, then a second for loop for all the towers except the ones chosen in the first loop. While only using the formula below from file lat.py
I have (this cannot be edited) ie. a line in my code must read
lat.distance_from_lat_long( lat1, long1, lat2, long2 )
Thus I need from the first for loop a lat1 and long1 which will stay the same until they read the lat2 and long2 of every other tower in the second for loop, then the 2nd tower goes to the first for loop and so on, and that will give me the distance between 2 of the towers.
A tower can work (count=+1) if from the nested for loop, the minimum of the lr[3] from lines is smaller than the 2 towers distance, then to return the name of the tower in the first for loop and which other towers it can work with, same for the 2nd, and which one that can and so on. Just a bit confused; wondering if anyone can help?
I'm not sure if this helps but I've been trying for hours and can't come up with anything. Here's my code right now and it's so bad maybe someone can help?
def Tower_Dist_From_Eachother(t,count):
for i in range(count):
for j in range(count):
lats = 0
longs = 0
tdist = lat.distance_from_lat_long(lats, longs, float(lr[j][1]), float(lr[j][2]))
def towers(l):
towname = []
for i in range(count):
towname.append(at[i][0])
for i in range(count):
lats += float(lr[i][1])
longs += float(lr[i][2])