# GradeRecordsJson Example # Answer questions based on the grade-records.json file import json fin = open("grade-records.json", "r") json_string = fin.read( ) arr = json.loads(json_string) # Next statement is for debugging # print(arr) # Enter desired first and last name. desired_first_name = input("Enter desired first name: ") desired_last_name = input("Enter desired last name: ") # Print the course name and course number # of all the courses that the desired # person has taken. for d in arr: if desired_first_name == d["first_name"] and \ desired_last_name == d["last_name"]: print(d["course_number"], d["course_name"]) print( ) # Print the total credit hours of the desired person. total_credit_hours = 0 for d in arr: if desired_first_name == d["first_name"] and \ desired_last_name == d["last_name"]: total_credit_hours += d["credit_hours"] print(f"Total credit hours: {total_credit_hours}") print( ) # Print the GPA of the desired person. grade_dict = {'A': 4, 'B': 3, 'C': 2, 'D': 1, 'F': 0} total_credit_hours = 0 total_grade_points = 0.0 for d in arr: if desired_first_name == d["first_name"] and \ desired_last_name == d["last_name"]: credit_hours = d["credit_hours"] grade = d["grade"] grade_points = grade_dict[grade] * credit_hours total_credit_hours += credit_hours total_grade_points += grade_points gpa = total_grade_points / total_credit_hours print(f"GPA: {round(gpa, 2)}")