# gpa.py """ Program to find student with highest GPA Has a Student Class in it """ import string import tkFileDialog 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 'LINE FROM FILE: ', infoStr name, hours, qpoints = string.split(infoStr,'-') return Student(name, hours, qpoints) def main(): # Get the filename #filename = raw_input("Enter name the grade file: ") #infile = open(filename, 'r') infile = tkFileDialog.askopenfile() # Construct some students best = makeStudent(infile.readline()) # Find the best student? HOW? # Get the GPA of student 1 for line in infile: currentStudent = makeStudent(line) if currentStudent.gpa() < best.gpa(): best = currentStudent # Close the file infile.close() # Display results 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()