Question: (10 Pts) [Task-5] Imagine a dictionary with the structurestudentid:[studentmajor,studentcgpa]. Assume majors are represented by strings like ‘CoE’, ‘EEE’, etc. Nowdefine a functionavgcgpabymajorthat takes such a dictionary and a string formajor as inputs and returns the average cgpa for all students with that major.Sample
-
Question: (10 Pts) [Task-5] Imagine a dictionary with the structurestudentid:[studentmajor,studentcgpa]. Assume majors are represented by strings like ‘CoE’, ‘EEE’, etc. Nowdefine a functionavgcgpabymajorthat takes such a dictionary and a string formajor as inputs and returns the average cgpa for all students with that major.Sample
(10 Pts) [Task-5] Imagine a dictionary with the structurestudentid:[studentmajor,studentcgpa]. Assume majors are represented by strings like ‘CoE’, ‘EEE’, etc. Nowdefine a functionavgcgpabymajorthat takes such a dictionary and a string formajor as inputs and returns the average cgpa for all students with that major.Sample input/Output:—In1 ={41251:[’CoE’,2.5], 42509:[’EEE’,3.1], 41713:[’CoE’,1.9], 41101:[’CoE’,2.7]}—print(avgcgpabymajor(In1,”CoE”))2.36 -
Here’s the best way to solve it.Solution
You can define the function `avgcgpabymajor` in Py…
OR