Question
You will do the following for this question. However, read the entire question before planning your solution. Create an input file named q2.dat in the
You will do the following for this question. However, read the entire question before planning your solution.
- Create an input file named q2.dat in the current directory where you stored this notebook with the following content.
[Jack Frost] [80, 50, 40, 20] [75, 75] [78.20, 77.20]
[James Potter] [82, 56, 44, 30] [80, 80] [67.90, 78.72]
[Dylan Rhodes] [77, 82, 23, 39] [78, 77] [80, 80]
[Jessica Stone] [67, 55, 77, 21] [40, 50] [69, 44.56]
[Tom Hanks] [29, 89, 60, 56] [65, 56] [50, 40.6]
-
There are four (4) separate fields in this file:
- name
- homeworks
- exams
- labs
Except for the name field, the remaining ones are represented in the same format as Python lists. However, note that this data is purely text!
-
Read, preprocess, and store this data in memory using a list of dictionaries like this:
[ { "name":"Jack Frost", "homeworks" : [80, 50, 40, 20], "exams" : [75, 75], "labs" : [78.20, 77.20] }, { ... } . . . ]
Note that the name field must be a string, and the remaining fields must be lists of floating-point numbers.
-
Write a Python function named display_grades( student_data ), which, given this list of dictionaries with student grade data in it, displays the data for all students in tabular format like this:
Student Name HW1 HW1 HW3 HW4 EX1 EX2 LAB1 LAB2 ------------------------------------------------------------------ Jack Frost 80 50 40 20 75 75 78.20 77.20 James Potter 82 56 44 30 80 80 67.90 78.72 Dylan Rhodes 77 82 23 39 78 77 80 80 Jessica Stone 67 55 77 21 40 50 69 44.56 Tom Hanks 29 89 60 56 65 56 50 40.6
- Write a Python function named compute_average( student_data, grade_type='homeworks' ), which computes the average for a given type of grade, the default being the homework grade. The grade_type parameter should accept homeworks, exams, or labs
- Write a Python function named sort_data( student_data, field_type='name', reverse=False ) that prints out the given student data in ascending order (unless reverse is True) according to the specified field type. For example, if the field type is name, then the student data should be printed out according to student name, in ascending order. The field_type should accept name, hw1, hw2, hw3, hw4, ex1, ex2, lab1, or lab2, matching each column in the data set.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started