# Name: ... # CSE 160 # Autumn 2022 # Final Exam from math import isclose # Problem 1 def create_match(my_team, score_sheet): """ Arguments: my_team (string): the team you are making a match for score_sheet (dict): a dictionary where the keys are the team names and values are a tuple of lists of the form: ([teams won against], [teams lost against]) Returns: a tuple of (chosen opponent team, winning average) where chosen opponent team is the team with the lowest winning average and winning average is the winning average of that team. """ # Your solution code should start here def test_match(actual, expected): assert actual[0] == expected[0] assert isclose(actual[1], expected[1]) def test_create_match(): scores1 = {"USA": (["France", "Brazil"], ["Korea"]), "France": (["Brazil"], ["USA"]), "Brazil": (["Korea"], ["France", "USA"]), "Korea": (["USA"], ["Brazil"])} test_match(create_match("USA", scores1), ("Brazil", 0.3333333333333333)) scores2 = {"USA": (["France"], []), "France": ([], ["USA"])} test_match(create_match("USA", scores2), ("France", 0)) # Problem 2 def search_item(inventory, search_terms, num_match): """ Arguments: inventory (dict): a dictionary where each key is an item (string) and each value is a list of (string) descriptive terms that apply to the item. search_terms (list): a list of strings representing the descriptive terms being searched for num_match (integer): the number of descriptive terms from search_terms that need to be in an item's list of descriptive terms before that item would be returned. Returns: an alphabetically sorted list of items who have at least num_match terms from search_terms in their list of descriptive terms. """ # Your solution code should start here def test_search_item(): inventory1 = {"banana": ["yellow", "long", "Fruit"], "pole": ["long", "plastic"], "yellow wig": ["wavy", "hair", "long", "yellow"], "chair": ["furniture", "brown"]} search_terms1 = ["long", "yellow", "Fruit", "tangy"] assert search_item(inventory1, search_terms1, 2) == ["banana", "yellow wig"] assert search_item(inventory1, search_terms1, 4) == [] # Problem 3 def todo_list(tasks): """ Arguments: tasks (list): a list of dictionaries where each dictionary represents a task with the keys "name", "priority", "time req", and "completed" Returns: a list of task names that are not completed, sorted by priority and time required. """ # Your solution code should start here def test_todo_list(): tasks_lst1 = [{"name": "CSE160 HW6", "priority": 1, "time req": 90, "completed": True}, {"name": "Grocery shopping", "priority": 2, "time req": 20, "completed": False}, {"name": "Doing the Laundry", "priority": 1, "time req": 60, "completed": False}, {"name": "Water plants", "priority": 2, "time req": 10, "completed": False}] assert todo_list(tasks_lst1) == ["Doing the Laundry", "Water plants", "Grocery shopping"] tasks_lst2 = [{"name": "Eating Lunch", "priority": 1, "time req": 30, "completed": True}, {"name": "Doing the dishes", "priority": 2, "time req": 10, "completed": False}, {"name": "Making Lunch", "priority": 1, "time req": 30, "completed": True}] assert todo_list(tasks_lst2) == ["Doing the dishes"] def main(): test_create_match() test_search_item() test_todo_list() if __name__ == "__main__": main() # You will answer a question about collaboration in part 2.