Question: please write the program in python: Extend the gpasort program so that it allows the user to sort a file of students based on gpa,

please write the program in python:

Extend the gpasort program so that it allows the user to sort a file of students based on gpa, name, or credits. Your program should prompt for the input file, the field to sort on, and the output file.

Here is my previous code:

# gpasort.py # A program to sort student information into GPA order.

from gpa import Student, makeStudent

def readStudents(filename): infile = open(filename, 'r') students = [] for line in infile: students.append(makeStudent(line)) infile.close() return students

def writeStudents(students, filename): outfile = open(filename, 'w') for s in students: print("{0}\t{1}\t{2}".format(s.getName(), s.getHours(), s.getQPoints()), file=outfile) outfile.close()

def main(): print("This program sorts student grade information by GPA") filename = input("Enter the name of the data file: ") data = readStudents(filename) data.sort(key=Student.gpa) filename = input("Enter a name for the output file: ") writeStudents(data, filename) print("The data has been written to", filename)

if __name__== '__main__': main()

And this is the extra info that to store in a seperate notepad file:

Adams, Henry 127 228

Computewell, Susan 100 400

DibbleBit, Denny 18 41.5

Jones, Jim 48.5 155

Smith, Frank 37 125.33

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!