Question: In Python, Use the file 'student_grades.csv'. This file comma-separated file contins four fields per line: the student ID, and then that student's scores on 3

In Python, Use the file 'student_grades.csv'. This file comma-separated file contins four fields per line: the student ID, and then that student's scores on 3 assignments. (Open the file in a text editor IDLE is fine, to see what it looks like).

Create a function called 'getStudentGrades()' that accepts a file name as a parameter. When you invoke the function on the students_grades.csv file, it should create a dictionary where the key is the student ID (i.e. the first field), and the value is a list that is made up of the remaining 3 fields in each row.

Because we are reading in from a text file, there is a ' ' at the end of each line. This means that the last item in each row) also has a ' ' character at the end right after the grade. Get rid of it by replacing the ' ' with an empty string: ''.

Also, since the grade items (though not the ID) should be integers (not strings), convert them to integers before inserting the list into the dictionary.

Your function should return your new dictionary.

Sample output:

>>> getStudentGrades('student_grades.csv')

{'600867': [33, 31, 0], '604548': [37, 33, 40], '283967': [40, 40, 40], '216637': [37, 38, 40], '205801': [40, 40, 37], '333044': [31, 0, 35], '634918': [30, 31, 25], '619028': [30, 36, 38], '246825': [40, 40, 40], '190891': [38, 39, 40], '218787': [40, 40, 40], '605099': [30, 22, 31], '278496': [39, 33, 38], '202645': [37, 32, 35]}

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!