내 기능은이 웹 사이트의 데이터를 가져 와서 지진의 위도, 경도, 깊이 및 강도를 수집하도록 설계되었습니다. 두 번째 함수 'colorCode'는 지진의 깊이를 받아서 색상 값을 반환하기로되어 있습니다. 이것은 내가 붙어있는 곳이다. if 문을 사용하여 int와 비교할 수 있도록 데이터를 부동 소수점으로 만들려고했으나 float로 변환 할 수 없다고합니다. 이견있는 사람?지진을 나열하는 기능
import urllib
#parseEarthquake: int --> list-of-float
def parseEarthquakeData(numberofearthquakes):
URLonWeb = urllib.urlopen("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.csv")
lines = URLonWeb.readlines()
numberoflines = len(lines)
numberoftimes = 0
index = 1
myaccumalator = []
for numberoftimes in range(numberofearthquakes):
while index < (numberofearthquakes + 1):
line = lines[index]
data = line.split(",")
latitude = float(data[1])
longitude = float(data[2])
depth = float(data[3])
magnitude = float(data[4])
if magnitude < 2.5:
magnitude = 2.5
myList = [[latitude, longitude, depth, magnitude]]
myaccumalator = myaccumalator + myList
index = index + 1
return(myaccumalator)
#return [latitude, longitude, depth, magnitude]
def colorCode(numberofQuakes):
data = parseEarthquakeData(2)
data =str(data)
realdata = data.split()
if realdata[2] <34:
print 'orange'
if realdata[2] >=34<70:
print 'yellow'
if realdata[2] >=70<150:
print 'green'
if realdata[2] >=150<300:
print 'blue'
if realdata[2] >=300<500:
print 'purple'
if realdata[2] >=500:
print 'red'
나는 모든'if' 문을 그렇게 들여 쓰고 싶지 않습니다. – IanAuld
정확한 오류 메시지는 무엇입니까? – tripleee