# Name # CSE 160 # Autumn 2025 # Coding Practice 5 # Problem 1 def sub_matrix(): ''' Write a function, sub_matrix, that takes in a matrix (doubly nested list) and an integer n, and returns a new matrix that replaces all numbers in the matrix which are divisible by n with 0. You may update the existing matrix or create a new one from scratch to return. ''' # Write your solution to Problem 1 here ''' Example: matrix = [ [5, 3, 7], [6, 10, 11], [9, 2, 0] ] sub_matrix(matrix, 2) --> [ [5, 3, 7], [0, 0, 11], [9, 0, 0] ] sub_matrix(matrix, 3) --> [ [5, 0, 7], [0, 10, 11], [0, 2, 0] ] ''' # Problem 2 def cheapest_grocery(): ''' Write a function, cheapest_grocery, that takes in a dictionay mapping grocery list items to a list of prices for the item across multiple brands. Each key is the name of the grocery (string) and each value is a list of prices (floats and ints) for that item from different brands. The function should add up all the cheapest prices for each item and return the total cost to buy those items at the lowest prices. Round your returned answer to 2 decimal places. DO NOT use Python's min() function. You can set a variable to an infinitely small value with the code float("inf"). You can round a value num to x decimal places by using the code round(val, x) ''' # Write your solution to Problem 2 here ''' Example: groceries = { "apple": [2.5, 1.3, 0.88], "butter": [5.25, 5], "milk": [3.49, 4.75, 2.99] } cheapest_grocery(groceries) --> returns 8.87 (0.88 + 5 + 2.99) ''' # Problem 3 def oldest_person(): ''' Write a function, oldest_person, that takes a list of dictionaries. Each dictionary represents a person ("name") and their age ("age"). Return the name of the oldest person in this list of dictionaries. ''' # Write your solution to Problem 3 here ''' Example: people = [ {"name": "Jane", "age": 30}, {"name": "John", "age": 45}, {"name": "Emma", "age": 21} ] oldest_person(people) --> "John" '''