Question: Write a function calculate_avg(d) which takes a dictionary of dictionaries as an input and calculates the average score for the math and science exams


Write a function calculate_avg(d) which takes a dictionary of dictionaries as an input and calculates the average score for the math and science exams given in this dictionary. There should be two return values: the average for math exams and the average for science exams (order is important: first math average, then science average). Return values should be floating-point numbers. Examples: test_d={Maria':{'math': 67, 'science': 45}, 'John': ('math: 88, 'science': 90), 'Sarah': {'math': 65, 'science': 90}, Albert': ('math': 74, 'science': 60}, 'Bob': {'math': 100, 'science': 65}} should return 78.8, 70.0 test_d (Nate': ('math': 47, 'science': 65). Claudia': ('math': 90, 'science': 90}, 'Meghan': ('math': 66, 'science': 87}, Harry': ('math': 77, 'science': 56}} should return 70.0, 74.5 Part B: (12 pts) Write a function higher grade(d) which takes a dictionary of dictionaries as an input and determines the course that each student has received a relatively higher grade. Your return value should be a list of tuples. Each tuple should consist of the name of the student and the course. RULE; If the science and math exam scores for any student are the same, then instead of the course name, you should have '-1' (string) inside the tuple. Examples: test_d = {Maria': ('math': 67,'science': 45). 'John': ('math: 88, 'science': 90}, 'Sarah': ('math': 65, 'science': 90}, 'Albert': ('math': 74, 'science': 60}, 'Bob': {'math': 100, 'science': 65}} should return [('Maria', 'math'). (John', 'science'), ('Sarah', 'science'). (Albert', 'math'), ('Bob', 'math')]] test_d={Nate': ('math': 47, 'science': 65}, Claudia': ('math': 90, 'science': 90}, Meghan': ('math': 66, 'science': 87). Harry': ('math': 77, 'science': 56}} should return [('Nate','science'), ('Claudia', '-1'), ('Meghan', 'science'), ('Harry', 'math')]

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 Programming Questions!