所以我有一個多行 一個文本文件,每一行都有名稱,等級,以及birthyear或學生,通過半冒號拆分列表是在一個文件
分隔怎樣使一個功能,以便它總結每一行中的所有第二項,然後對它們進行平均?
例如,
mary; 0; 1995
jay; 50; 1995
classAverage = 25
與此真的混淆。
這裏是我的代碼,到目前爲止,它並沒有給我的錯誤,但是當我打印出來說<function classAverage at 0x0000000004C1ADD8>
from kiva.constants import LINES
def process(name):
f = open(name)
answer = []
for line in f:
answer.append(line.strip())
return answer
def classAverage(data):
data = process(filename)
data.split()
adding = []
for line in data:
adding = adding + data[1]
return adding/(line)
if __name__ == '__main__':
filename = "grades.txt"
data = process(filename)
for each in data:
print each
print classAverage(data)
#print "Average grade is ", classAverage(data)
year1 = 1995
year2 = 1997
print "Number born from ",year1,"to",year2,"is",
#print howManyInRange(data, year1, year2)