如何修复代码中的错误。每当我尝试运行它时,'float'对象都没有出现“ getitem ”属性。我试图将所有计算值放在一个类似于表格的格式,但错误仍然出现。 这是代码。它比我想象的要长一点。错误是在范围内的i ...
sumlat = 0.0
sumdep = 0.0
sumdist = 0.0
lat1 = []
dep1 = []
d1 = []
northings = []
eastings = []
adjdep = []
adjlat = []
import math
n = input('\nEnter Number of Corners:')
northings += [input('Northings of Point 1:')]
eastings += [input('Eastings of Point 1:')]
def compLatDep (b, d): #function compLatDep
return (b, d)
def degAzi (deg, mi, sec):
return (deg, mi, sec)
#I.
for i in range (0,n):
if n > i+1:
print '\nLine %d-%d.' % (i+1, i+2)
else:
print '\nLine %d-%d.' % (i+1, 1)
b = raw_input('Azimuth (from the South in D-M-S):') #follow the format in entering the given azimuth
myString = b
deg = myString.split("-")[0] #myString.split("-") method results to an input string split and returned the list of string split
deg = float(deg)
mi = myString.split("-")[1]
mi = float(mi)
sec = myString.split("-")[2]
sec = float(sec)
decimal = deg + (mi/60) + (sec/3600) #conversion of dms into decimal degrees
d = input('Distance (in meters):')
d1 += [d]
sumdist += d
lat, dep = compLatDep (b,d)
dep = -d * math.sin(math.radians(decimal)) #the azimuth should be converted into radians for this import/formula to work, given formula in finding the dep of a corner
dep1 += [dep]
sumdep += dep
lat = -d * math.cos(math.radians(decimal)) #given formula in finding the lat of a corner
lat1 += [lat]
sumlat += lat
for i in range(len(dep1)):
corr = -sumdep * d1[i] / sumdist #formula in finding the correction to be applied in each departure
corrdep = corr + dep1[i] # formula for corrected departure of each corner
adjdep += [corrdep]
for i in range(len(lat1)):
corr = -sumlat *d1[i] / sumdist #formula in finding the correction to be applied in each latitude
corrlat = corr + lat1[i] #formula for corrected latitude of each corner
adjlat += [corrlat]
for i in range(len(lat1)):
north = northings [i] + lat1 [i]
northings += [north]
for i in range(len(dep1)):
east = eastings [i] + dep1 [i]
eastings += [east]
LEC = math.hypot(sumlat, sumdep) #imported from math module to find the LEC of a closed loop traverse
print '\n\tLEC: %f' % LEC
print '\tREC: 1:', (sumdist/LEC)
print '\t : 1:', (int(sumdist/LEC)) #rounded down to the nearest integer
print '%s\t%10s\t%14s\t%14s\t%14s\t%14s\t%14s' % ('Line', 'Azimuth', 'Distance', 'Adj Lat', 'Adj Dep', 'Northings', 'Eastings')
for i in range (1,(n+1)):
if(i == n):
print '%d-%d\t%10f\t%14f\t%14f\t%14f\t%14f\t%14f' %(i, 1, decimal[i], d1[i], adjlat[i], adjdep[i], northings[i], eastings[i])
else:
print '%d-%d\t%10f\t%14f\t%14f\t%14f\t%14f\t%14f' %(i, i + 1, decimal[i], d1[i], adjlat[i], adjdep[i], northings[i], eastings[i])