class Student: def __init__(self,name,hours,qpoints): self.name = name self.hours = float(hours) self.qpoints = float(qpoints) def getName(self): return self.name def getHours(self): return self.hours def getQPoints(self): return self.qpoints def getGPA(self): return self.qpoints / self.hours def makeStudent(line): """ creates an instance of class Student; line is a line from the file formatted as LastName, FirstName hours qpoints """ name, hours, qpoints = line.split(" ") return Student(name,hours,qpoints) def main(): # get the file name fname = input("Enter the file name:") source = open(fname) student = source.readline() # read the first line from the file stu = makeStudent(student) # current student with greatest GPA for line in source: # read the rest of the lines from the file nextStu = makeStudent(line) # if GPA of the students if greatest GPA is less than the current student's GPA if stu.getGPA() < nextStu.getGPA(): stu = nextStu # update the information about the student with greatest GPA print("{0} has the highest GPA of {1} and accumulated {2} hours".format(stu.getName(),round(stu.getGPA(),2),stu.getHours())) main()