【发布时间】:2013-07-18 07:50:23
【问题描述】:
我在通过 while 循环传递值时遇到问题。我已经在下面用一些伪代码进行了编码,但我仍然不确定如何实现结果,但如果可以的话,我在下面附上了我的代码以提供帮助。通过 while 循环传递值的错误部分
首先,我的双重价值列表如下。指名称,东,北
Stationlist = [['perth.csv','476050','7709929'],['sydney.csv','473791','7707713'],['melbourne.csv','46576','7691097']]
这是我正在使用的代码:
Import math
global Eastingbase
global Northingbase
Eastingbase=476050
Northingbase= 7709929
Def calculateDistance (northingOne, eastingOne, northingTwo, eastingTwo):
Base =100000
deltaEasting = eastingTwo -eastingOne
deltaNorthing = northingTwo -northingOne
Distance = (deltaEasting**2 + deltaNorthing**2) **0.5
If Distance < Base:
Return Distance
Def Radius():
1000
L=0
while L <= Len(Stationlist):
if calculateDistance(Eastingbase, Northingbase, Stationlist(row L, column 2),Stationlist(row L, column 3)) < Radius:
Relevantfilename = StationList (row L, column 1)
print Relevantfilename
L = +1
我的错误是我不确定如何将站列表中的值传递到 while 循环中,然后继续循环。我尝试使用双重列表理解,即 [0][1] 来传递名称,但它不起作用。将加 1 添加到 L 似乎也不会继续循环。有没有办法将一行中的所有值传递到 while 循环中并对其进行测试。??即传递 Perth.csv 到 Stationlist(L 行,第 1 列),476050 到 Stationlist(L 行,第 2 列)和 7709929 到 Stationlist(L 行,第 3 列)
完成后,重复墨尔本和悉尼的数据
【问题讨论】:
-
您没有将 L 加一。您将其设置为 +1。正确的语法是 L += 1
-
@andyn 谢谢 :) 我什至没有意识到。我面前的手写代码甚至说 L+= 1 但我还没有转置它。感谢您的帮助
标签: python list parsing while-loop