# gpa.py """ Program to find student with highest GPA Has a Student Class in it """ import string class Student: """ Simulates a student with a GPA, number of hours they have passed so far, and number of quality points they have accumlated. """ def __init__(self, name, hours, qpoints): """ Initialize the student """ self.name = name self.hours = float(hours) self.qpoints = float(qpoints) def getName(self): """ Get the name of the Student """ return self.name def getHours(self): """ Get the hours the Student has completed """ return self.hours def getQPoints(self): """ Get the quality points the student has accumulated """ return self.qpoints def gpa(self): """ Return the GPA """ return self.qpoints/self.hours # ------------------------------------ # No longer in the class # ------------------------------------ def makeStudent(infoStr): print infoStr name, hours, qpoints = string.split(infoStr,'-') return Student(name, hours, qpoints) def main(): filename = raw_input("Enter name the grade file: ") infile = open(filename, 'r') best = makeStudent(infile.readline()) for line in infile: s = makeStudent(line) if s.gpa() > best.gpa(): best = s infile.close() print "The best student is:", best.getName() print "hours:", best.getHours() print "GPA:", best.gpa() # This makes sure that the main program ONLY runs if # this is the outermost module being called if __name__ == '__main__': main()