S
Shawn Minisall
I'm trying to unpack a list of 5 floats from a list read from a file and
python is telling me 5 variables are too many for the string.split
statement. Anyone have any other idea's? NOTE: the only reason I
convert it to a float instead of just leaving it as a string in the loop
is because I have to have it printed out as a float besides the names
and then the average displayed underneath
thx
#read in data line by line
for line in infile:
mylist = string.split(line)
firstName[counter] = mylist[0]
lastName[counter] = mylist[1]
grades[counter] = float(mylist[2])
print firstName[counter],
lastName[counter],":","\t\t",grades[counter]
#increment counter
counter = counter + 1
#calculates and prints average score
grades = str(grades)
num1, num2, num3, num4, num5 = string.split(grades,",")
average = float(num1 + num2 + num3 + num4 + num5) / 5
print
print "Average:"
python is telling me 5 variables are too many for the string.split
statement. Anyone have any other idea's? NOTE: the only reason I
convert it to a float instead of just leaving it as a string in the loop
is because I have to have it printed out as a float besides the names
and then the average displayed underneath
thx
#read in data line by line
for line in infile:
mylist = string.split(line)
firstName[counter] = mylist[0]
lastName[counter] = mylist[1]
grades[counter] = float(mylist[2])
print firstName[counter],
lastName[counter],":","\t\t",grades[counter]
#increment counter
counter = counter + 1
#calculates and prints average score
grades = str(grades)
num1, num2, num3, num4, num5 = string.split(grades,",")
average = float(num1 + num2 + num3 + num4 + num5) / 5
print "Average:"