infile
Mary 15
Joe 13
Dustin 12
code
name=" "
age=0
average_age = 0
invites={}
infile = open("party.txt", "r")
for line in infile:
parts=line.split()
print parts #prints the correct values
name=parts[0] #gives me index error here
age=parts[1] # also here
average_age += age
invites[name]=age
infile.close()
average_age /= float(len(age))
print ("%.1f %s" % (average_age))
infile Mary 15 Joe 13 Dustin 12 code name=" " age=0 average_age = 0 invites={} infile = open("party.txt", "r") for line in infile: parts=line.split() print parts #prints the correct values name=parts[0] #gives me index error here age=parts[1] # also here average_age += age invites[name]=age infile.close() average_age /= float(len(age)) print ("%.1f %s" % (average_age))