[Tutor] Reading from files problem
Chris Castillo
ctcast at gmail.com
Mon Apr 20 01:45:35 CEST 2009
I am trying to open a text file and read multiple lines containing the
following:
745777686,Alam,Gaus,CIS,15,30,25,15,5,31,15,48,70,97
888209279,Anderson,Judy,Math Ed,14,30,30,13,11,30,16,18,58,72
I want to ask the user for the student number, check to see if that
number is even valid and display something like:
last name, first name, student number, major
time info was accessed(i know i need to import time module)
exam scores
homework scores
average score for the class
#Open and read text file
gradesfile = open("grades.dat", "rfor lines in gradesfile:
lines = lines.split(",")
identifier = lines[0]
lastname = lines[1]
firstname = lines[2]
major = lines[3]
hw1 = lines[4]
hw2 = lines[5]
hw3 = lines[6]
hw4 = lines[7]
hw5 = lines[8]
hw6 = lines[9]
hw7 = lines[10]
test1 = lines[11]
test2 = lines[12]
test3 = lines[13]
totalpoints = 550
hwgrades = float(hw1) + float(hw2) + float(hw3) + float(hw4) +
float(hw5) + float(hw6) + float(hw7)
testgrades = float(test1) + float(test2) + float(test3)
studentpoints = float(hwgrades) + float(testgrades)
avgrades = round(float(studentpoints / totalpoints) * 100.0, 2)
print identifier
gradesfile.close()
That's what I have so far but I have a feeling I shouldn't use a for
loop. I would really like any help trying to figure out this program.
Thanks in advance.
More information about the Tutor
mailing list