I would like to create a column to show the average of two columns, y[12] and y[13] from a txt file I tried it like below
It doesn't work though
Code:
f = open(’weather.txt’, ’r’)
g = open(’weather.html’, ’w’)
l = f.readlines()
g.write("<html>\n<head>\n<title>Weather by city</title>\n</head>\n")
g.write("<body>\n<table border=’2’><tr><th>City</th>"+
"<th>Average.</th></tr>\n")
for x in l:
y = x.split(",")
if len(y) > 13:
g.write("<tr><td>" + y[1] + "</td><td>" +(sum( y[12] , y[13])/2) +
"</td></tr>\n")
g.close()
f.close()
Comment