# Name: ... # CSE 160 # Summer 2023 # Checkin 7 # Problem 1 def student_grades(student_gradebook, assignment_num): ''' Given the following code, read the stacktrace and resolve the bugs to produce the expected behavior. Expected behavior: Given a dictionary where the keys are a two-element tuple containing a student's first and last name in the format (firstname, lastname) and the values are a list with the student's performance on the last three assignments in the format (grade1, grade2, grade3), return a set containing the firstname lastname tuples of each student who scored at least a 50 on the specified assignment Hint: We expect there to be three bugs to fix Arguments: student_gradebook: a dictionary where the keys are a two-element tuple containing a student's first and last name in the format (firstname, lastname) and the values are a list with the student's performance on the last three assignments in the format (grade1, grade2, grade3) assignment_num: an integer representing the assignment number to be checked. Will always be less than 5. Returns: a set of tuples where each tuples has the format (firstname, lastname). If no students have the required grade for the assignment, return an empty set ''' student_name = {} for name in student_gradebook.items(): student_grades = student_gradebook[name] if (student_grades[assignment_num] >= 50): student_name = student_name | set([name]) return student_name assert student_grades({("Tweety", "Bird"): [90, 50, 39]}, 1) == \ {("Tweety", "Bird")} assert student_grades({("Tweety", "Bird"): [90, 50, 39]}, 3) == set() assert student_grades({("Tweety", "Bird"): [90, 50, 39]}, 2) == \ {("Tweety", "Bird")} assert student_grades({("Hector", "Bulldog"): [51, 30, 100], ("Tweety", "Bird"): [90, 50, 39]}, 3) == \ {("Hector", "Bulldog")} assert student_grades({("Hector", "Bulldog"): [51, 30, 100], ("Tweety", "Bird"): [90, 50, 39]}, 2) == \ {("Tweety", "Bird")} assert student_grades({("Hector", "Bulldog"): [51, 30, 100], ("Tweety", "Bird"): [90, 50, 39]}, 1) == \ {("Tweety", "Bird"), ("Hector", "Bulldog")} assert student_grades({("Sylvester", "Stallone"): [19, 76, 76], ("Hector", "Bulldog"): [51, 30, 100], ("Tweety", "Bird"): [90, 50, 39]}, 1) == \ {("Tweety", "Bird"), ("Hector", "Bulldog")} assert student_grades({("Sylvester", "Stallone"): [19, 76, 76], ("Hector", "Bulldog"): [51, 30, 100], ("Tweety", "Bird"): [90, 50, 39]}, 3) == \ {("Sylvester", "Stallone"), ("Hector", "Bulldog")} # Problem 2 def mutability_exercise(input_set, input_list, input_dict): ''' Given a set, list and dictionary do the following operations in the given order: a) modify the set to contain all the original elements plus the keys from the dictionary b) Replace all values in the dictionary with '160' c) Return a list with all the elements found in the set removed but with original order preserved Note: Because modification of the set occurs before adding new elements to the returned list, the returned list will also have any values that appear as keys in the dictionary removed Arguments: input_set: a set of integers input_list: a list of integers input_dict: a dictionary where both the key and value are integers Returns: A list containing all the elements of the input_set with all elements of input_set removed ''' # your solution code should start here input_set_one = {1, 2, 3, 4, 5} input_list_one = [1, 6, 0, 15] input_dict_one = {21: 5, 3: 6, 15: 2} output_list_one = mutability_exercise(input_set_one, input_list_one, input_dict_one) assert input_set_one == {1, 2, 3, 4, 5, 21, 15} assert input_list_one == [1, 6, 0, 15] assert input_dict_one == {21: 160, 3: 160, 15: 160} assert output_list_one == [6, 0] input_set_two = {2, 4, 8, 16, 4000} input_list_two = [-2, 4, -8, 3] input_dict_two = {160: 160, 2: 3, 4000: 120} output_list_two = mutability_exercise(input_set_two, input_list_two, input_dict_two) assert input_set_two == {2, 4, 8, 16, 4000, 160} assert input_list_two == [-2, 4, -8, 3] assert input_dict_two == {160: 160, 2: 160, 4000: 160} assert output_list_two == [-2, -8, 3]