class Student: name = None id = None gpa = None # Student specification ends here def outputStudents(student, nStudents): for i in range(nStudents): print("Name =", "{:30}".format(student[i].name), end="") print(" ID =", "{:07}".format(student[i].id), end="") print(", gpa =", student[i].gpa) # outputStudents ends here # main program starts here try: # open a file for input fin = open("students.txt") # create an empty list MAX_STUDENTS = 30 # list capacity nStudents = 0 # initially empty list student = [Student() for i in range(MAX_STUDENTS)] except: print("file not found") exit() # end the program NOW # read and save the records for lineFromFile in fin: aStudent = Student() aStudent.name = lineFromFile.strip() aStudent.id = int(fin.readline().strip()) aStudent.gpa = float(fin.readline().strip()) fin.readline() # skip the ---------- separator # add record to list, if it's not full if (nStudents < MAX_STUDENTS): student[nStudents] = aStudent nStudents += 1 fin.close() # done with the file # sort the students by name for i in range(nStudents): for j in range(i + 1, nStudents): if student[i].name.lower() > student[j].name.lower(): student[i],student[j] = student[j],student[i] outputStudents(student, nStudents)