Need help to solve: IndexError: list index out of range
The code is to read the info in the text and print out the city and their highest temp. And once all is done, it should close the file.
Assistance please. Much thanks.
!curl https://raw.githubusercontent.com/MicrosoftLearning/intropython/master/world_temp_mean.csv -o mean_temp.txt
temp_file = open('mean_temp.txt','a+')
temp_file.write("Rio de Janeiro,Brazil,30.0,18.0")
temp_file.seek(0,0)
headings = temp_file.readline()
headings = headings.split(',')
#print(headings)
city_temp = temp_file.readline()
while city_temp:
city_temp = temp_file.readline()
city_temp = city_temp.split(',')
print(headings[0].capitalize(),"of",city_temp[1],headings[2],"is",city_temp[2],"Celsius.")
temp_file.close()
Here are the contents of temp_file.txt:
city,country,month ave: highest high,month ave: lowest low Beijing,China,30.9,-8.4 Cairo,Egypt,34.7,1.2 London,UK,23.5,2.1 Nairobi,Kenya,26.3,10.5 New York City,USA,28.9,-2.8 Sydney,Australia,26.5,8.7 Tokyo,Japan,30.8,0.9