Question
Use Python ( Spyder ) to program the solutions to the tasks. This dictionary contains data describing student performance in a course. The structure of
Use Python ( Spyder ) to program the solutions to the tasks. This dictionary contains data describing student performance in a course. The structure of each key-value pair in that dictionary is as follows: (FirstName,Gender,Class):[ListOfTestGrades] . Note that the keys in this dictionary are tuples and the values are lists.
Overview: Code a function named select(dict/keys,index) that does the following: (Also, see tasks at the bottom)
Receives these arguments:
- dict/keys: this can be either the entire studentPerf dictionary or the keys of that dictionary
- index is the index of the data element in the keys (which are of a tuple data type) that you want to extract into a list
Returns a list of the data elements from the keys of the dictionary studentPerf relating to a specified index, where each possible value is listed only once. For example, if the keys in the dictionary were [('John',2),('Julie',2),('John',3),('John',1),('Julie',1),('Julie',3)], then this function should return ['John','Julie'] for index 0, and [1,2,3] for index 1.
- Code in the main part of the program to perform the tasks below.
o You will use function select()in some, but not all of the tasks below.
Data:
def select(dict/key, index):
# Insert function code here
studentPerf = {('Jeffery','male','junior'):[0.81,0.75,0.74,0.8],
('Able','male','senior'):[0.87,0.79,0.81,0.81],
('Don','male','junior'):[0.82,0.77,0.8,0.8],
('Will','male','senior'):[0.86,0.78,0.77,0.78],
('John','male','junior'):[0.74,0.81,0.87,0.73],
('Patrick','male','senior'):[0.9,0.82,0.94,0.79],
('Iggie','male','senior'):[0.8,0.88,0.87,0.88],
('Harvey','male','sophomore'):[0.66,0.76,0.79,0.76],
('Ralph','male','senior'):[0.81,0.78,0.8,0.89],
('Edward','male','senior'):[0.81,0.87,0.88,0.84],
('Eric','male','junior'):[0.76,0.73,0.83,0.76],
('Wallace','male','sophomore'):[0.7,0.8,0.79,0.8],
('Ronald','male','senior'):[0.76,0.78,0.82,0.83],
('Perry','male','junior'):[0.83,0.87,0.77,0.75],
('Robert','male','senior'):[0.92,0.8,0.82,0.84],
('Thomas','male','junior'):[0.76,0.72,0.8,0.72],
('Mark','male','senior'):[0.87,0.79,0.81,0.83],
('Santiago','male','junior'):[0.77,0.81,0.74,0.75],
('Diego','male','senior'):[0.78,0.8,0.8,0.8],
('Samuel','male','senior'):[0.8,0.89,0.82,0.87],
('Alejandro','male','senior'):[0.86,0.79,0.87,0.8],
('Hector','male','junior'):[0.79,0.72,0.78,0.72],
('Jin','male','senior'):[0.83,0.79,0.9,0.8],
('Yu Yan','male','junior'):[0.75,0.72,0.8,0.81],
('Fei Hung','male','senior'):[0.86,0.91,0.84,0.9],
('Chen','male','senior'):[0.76,0.77,0.84,0.88],
('Wei','male','senior'):[0.84,0.86,0.78,0.88],
('Fang','male','senior'):[0.78,0.89,0.89,0.86],
('Anders','male','junior'):[0.8,0.73,0.78,0.8],
('Nils','male','junior'):[0.82,0.84,0.79,0.76],
('Arne','male','sophomore'):[0.68,0.73,0.81,0.72],
('Jochen','male','junior'):[0.82,0.86,0.8,0.73],
('Jurgen','male','junior'):[0.68,0.78,0.78,0.81],
('Carl','male','junior'):[0.72,0.82,0.79,0.76],
('Thor','male','senior'):[0.91,0.84,0.9,0.89],
('Harold','male','junior'):[0.76,0.78,0.8,0.79],
('Aditya','male','senior'):[0.83,0.87,0.82,0.83],
('Varun','male','senior'):[0.76,0.86,0.88,0.79],
('Shantanu','male','senior'):[0.79,0.81,0.78,0.78],
('Krishnan','male','sophomore'):[0.66,0.76,0.74,0.8],
('Manoj','male','junior'):[0.75,0.77,0.72,0.81],
('Rahul','male','sophomore'):[0.73,0.67,0.68,0.7],
('Rohit','male','sophomore'):[0.75,0.75,0.77,0.74],
('Vijay','male','senior'):[0.91,0.84,0.83,0.9],
('Sophie','female','senior'):[0.83,0.96,0.9,0.95],
('Lynn','female','senior'):[0.97,0.85,0.93,0.88],
('Bailey','female','sophomore'):[0.83,0.78,0.74,0.75],
('Karen','female','junior'):[0.79,0.88,0.9,0.84],
('Audrey','female','junior'):[0.79,0.85,0.86,0.81],
('Suzie','female','junior'):[0.81,0.82,0.93,0.88],
('Marissa','female','senior'):[1,0.92,0.95,0.91],
('Hong','female','senior'):[0.92,0.93,0.88,1],
('Susudio','female','sophomore'):[0.75,0.85,0.85,0.81],
('Clarissa','female','junior'):[0.79,0.84,0.82,0.83],
('Layla','female','junior'):[0.87,0.88,0.87,0.92],
('Alanis','female','sophomore'):[0.75,0.77,0.76,0.81],
('Erin','female','senior'):[0.88,0.93,0.97,0.91],
('Chantel','female','junior'):[0.85,0.84,0.85,0.79],
('Laura','female','junior'):[0.82,0.84,0.94,0.88],
('Laurie','female','senior'):[0.86,0.93,0.89,0.94],
('Elle','female','senior'):[0.98,0.92,0.98,0.99],
('Alisa','female','sophomore'):[0.75,0.86,0.89,0.83],
('Else','female','junior'):[0.91,0.8,0.84,0.88],
('Anna','female','senior'):[0.88,0.95,0.97,0.83],
('Dorothy','female','junior'):[0.94,0.94,0.89,0.84],
('Bridgette','female','junior'):[0.85,0.8,0.84,0.8],
('Sophia','female','senior'):[0.93,0.96,0.94,0.87],
('Bianca','female','junior'):[0.83,0.79,0.93,0.9],
('Mia','female','junior'):[0.89,0.85,0.89,0.91],
('Monika','female','junior'):[0.89,0.82,0.9,0.91],
('Emma','female','senior'):[0.96,0.85,0.88,0.97],
('Margaurite','female','junior'):[0.88,0.86,0.85,0.79],
('Helga','female','senior'):[0.9,0.85,0.84,0.89],
('Patsy','female','junior'):[0.84,0.88,0.9,0.86],
('Phoebe','female','senior'):[0.85,0.94,0.88,0.97],
('Vivian','female','junior'):[0.78,0.86,0.89,0.77],
('Breeanne','female','sophomore'):[0.74,0.82,0.84,0.85],
('Charlotte','female','junior'):[0.77,0.84,0.87,0.77],
('Amelia','female','senior'):[0.87,1,0.89,0.92],
('Olivia','female','junior'):[0.84,0.78,0.85,0.91],
('Isabella','female','sophomore'):[0.78,0.86,0.83,0.8],
('Evelyn','female','junior'):[0.85,0.88,0.91,0.88],
('Abagail','female','senior'):[0.93,0.94,0.87,0.84],
('Ella','female','sophomore'):[0.75,0.82,0.76,0.87],
('Ava','female','junior'):[0.88,0.83,0.9,0.81],
('Madison','female','senior'):[0.93,0.97,0.9,0.95],
('Chloe','female','junior'):[0.88,0.88,0.94,0.84],
('Grace','female','junior'):[0.9,0.85,0.88,0.83],
('Aubrey','female','junior'):[0.83,0.77,0.83,0.8],
('Mila','female','sophomore'):[0.82,0.85,0.79,0.83],
('Zoe','female','sophomore'):[0.82,0.81,0.83,0.81],
('Leah','female','sophomore'):[0.8,0.84,0.78,0.75],
('Stella','female','senior'):[0.93,0.9,0.96,0.92],
('Claire','female','sophomore'):[0.83,0.79,0.86,0.86],
('Aurora','female','senior'):[0.92,0.87,0.91,0.9],
('Lucy','female','senior'):[0.82,0.82,0.96,0.88],
('Samantha','female','senior'):[0.92,0.95,1,0.93],
('Tabitha','female','senior'):[0.97,0.87,0.89,0.88]}
# Complete the main program code below using the listed variables:
sophNames =
classes = select()
genders = select()
dictAvgGrade =
gradesSoph =
dictDemClass =
dictDemClass =
dictDemGender =
dictDemGender =
dictGradeClass =
TASKS
Variable Name for Result : sophNames
Data Type for Result : List
Task: List of all the first names of the students who are sophomores.
Variable Name for Result: classes
Data Type for Result: List
Task: Use the select() function to generate a unique list of all the different values listed in the key tuple in the index position 2, that is, the element denoting a student's class. "Unique" means that this list can have no repeating values.
Variable Name for Result: genders
Data Type for Result: List
Task: Use the select() function to perform a similar task to the one above, but only for the key elements in the Index 1 position.
Variable Name for Result: dictAvgGrade
Data Type for Result: Dictionary
Task: Generate a new dictionary with the same keys as in studentPerf and values that represent the average of each student's four test grades.
Variable Name for Result: gradesSoph
Data Type for Result: List
Task: Extract the data from the dictAvgGrade dictionary and create a list of the average grades for all sophomores.
Variable Name for Result: dictDemClass
Data Type for Result: Dictionary
Task: Use the result for the list classes above to initialize this dictionary, where the elements in the classes list are the keys and the value for each key is zero.
Variable Name for Result: dictDemClass
Data Type for Result: Dictionary
Task: Use the dictionary, which was initialized in the task above with these keys: 'sophomore', 'junior', and 'senior'. Update the values in this dictionary so that they reflect the number of occurrences of each of the keys.
Variable Name of Result: dictDemGender
Data Type for Result: Dictionary
Task: Use the result for the list genders above to initialize this dictionary, where the keys are the elements in the genders list and the value for each key is 0.
Variable Name of Result: dictDemGender
Data Type for Result: Dictionary
Task: Update the values of the dictDemGender dictionary to reflect the number of 'female' and 'male' students in the studentPerf dictionary.
Variable Name of Result:dictGradeClass
Data Type for Result: Dictionary
Task: Generate a dictionary with three keys, 'sophomore', 'junior', and 'senior'. The values for each key should reflect the average grade of all students in the respective classes.
Place useful comments in your code so that you would remember your programming logic if you were to revisit this code later.
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