# 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 worst = makeStudent(infile.readline()) # Find the best student? HOW? # Loop through the file and read each student for line in infile: currentStudent = makeStudent(line) # If the stduent is better than the last student, keep it if currentStudent.gpa() < worst.gpa(): worst = currentStudent # Close the file infile.close() # Display results print "The worst student is:", worst.name print "hours:", worst.getHours() print "GPA:", worst.gpa() # This makes sure that the main program ONLY runs if # this is the outermost module being called if __name__ == '__main__': main()