[Tutor] Reading Data From File

ctcast at gmail.com ctcast at gmail.com
Sat Jul 25 20:44:29 CEST 2009

grades = []
names = []
gradeTotal = 0
numStudents = 0

inputFile = open("input.txt", "r"

for line in inputFile:
if line.strip().isdigit():
grade = float(line)
if grade != 0.0:
gradeTotal += grade
grade = grades.append(grade)
name = line.strip()
name = names.append(name)

This just loops over the entire file basically and just continually adds  
the grades to the grades list and names to the names list. How do I just  
process each student's set of grades before moving on to the next one  
(since there is a zero terminating value telling the loop that a new  
student and his or her grades are about to follow)

By the way I'm not worrying about determining the letter grade average  
right now, i'm importing a module I wrote after I figure this part out.

On Jul 25, 2009 8:34am, bob gailer <bgailer at gmail.com> wrote:
> I concur with wesley and dave re homework.

> Some questions to consider:

> do you know how to open a file?

> do you know how to read a line from an opened file?

> do you know how to incorporate reading lines in a loop?

> do you know how to determine whether a character is "numeric"?

> do you know how to print a line?

> what is the criteria for determining A, BC, D, or F average?

> --

> Bob Gailer

> Chapel Hill NC

> 919-636-4239

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090725/9b78569a/attachment.htm>

More information about the Tutor mailing list