Write a program that reads a list of students and their grades from a file and outputs to a JSON file.
- Read / Write files
- Standard collections (List, Dictionary)
- Common data tasks (Order, Average, Find Max and Min)
Write a program that reads a list of students and their grades from a file.
The file should be formatted as follows:
student_name, grade
For example, the following file would contain the grades for three students:
John Doe, 80
Jane Doe, 90
Peter Smith, 75
The program should then do the following:
- Create a dictionary where the keys are the student names and the values are the grades.
- Sort the students by their grades in decreasing order.
- Find the highest and lowest grades.
- Calculate the class average.
- Create a dictionary with the following keys and corresponding values:
high_score
: Highest Scorelow_score
: Lowest Scoretotal_students
: Total Number of Studentsavg_score
: Average Scorestudents
: List of students and scores ordered by score.
- Serialize the dictionary to JSON format in a file called
output.json
.
Example Output:
{
"high_score": 90,
"low_score": 75,
"total_students": 3,
"avg_score": 81.6,
"students": [
["Jane Doe", 90],
["John Doe", 80],
["Peter Smith", 75]
]
}