# Name: ... # CSE 160 # Autumn 2021 # Final Exam # Problem 1 def least_exp_store(ingred_price_dict, ingred1, ingred2): ''' Arguments: ingred_price_dict: a dict of price_lists ingred1, ingred2: 2 strings representing ingredients Returns: A list containing two elements: a string representing the least expensive store to purchase ingred1 and ingred2 at, and the total cost of the two ingredients at that store. If there is a tie for lowest cost, returns the store with the higher index. ''' # your solution code should start here def test_least_exp_store(): ingred_price_dict = {"Flour": [1, 2, 3], "Sugar": [20, 19, 24], "Butter": [2, 3, 4], "Molasses": [6, 7, 5]} assert least_exp_store(ingred_price_dict, "Butter", "Molasses") == ["Store 0", 8] assert least_exp_store(ingred_price_dict, "Flour", "Sugar") == ["Store 1", 21] ingred_price_dict2 = {"Flour": [10], "Sugar": [30]} assert least_exp_store(ingred_price_dict2, "Flour", "Sugar") == ["Store 0", 40] # Problem 2 def customer_loyalty(visit_tracker): ''' Arguments: visit_tracker: a dictionary mapping customer names to a list of their visits to bubble tea stores Returns: a dictionary mapping stores to a set of their loyal customers. If a store does not have any loyal customers, it is not included in the returned dictionary. If the visit_tracker is empty or if there are no loyal customers, return an empty dictionary. ''' # your solution code should start here def test_customer_loyalty(): visit_tracker1 = {"Evan": ["Ding Tea", "Ding Tea", "Yi Fang", "Ding Tea", "Ding Tea"], "Izzy": ["Boba Up", "Ding Tea", "Boba Up", "Boba Up", "Ding Tea", "Ding Tea", "Ding Tea"]} assert customer_loyalty(visit_tracker1) == {"Boba Up": {"Izzy"}, "Ding Tea": {"Evan", "Izzy"}} visit_tracker2 = {"Jackie": ["DIY Tea", "DIY Tea", "DIY Tea"], "Evan": ["Yum Tea", "Ding Tea", "Yi Fang", "Yum Tea", "Yum Tea"]} assert customer_loyalty(visit_tracker2) == {"DIY Tea": {"Jackie"}} # Problem 3 def never_win(match_tuples): ''' Arguments: match_tuples: a list of tuples that are size 2 representing matches played. Each tuple is in the form (string, boolean), which represents the champion played for the match and whether the match was won (True for won, False for lost). Assume match_tuples is not empty. Returns: a list of the unique champions that have no matches won in match_tuples, sorted in alphabetical order. Returns an empty list if there are no champions with zero matches won. ''' # your solution code should start here def test_never_win(): win_list1 = [("Ezreal", False), ("Yasuo", False), ("Teemo", False), ("Jinx", True), ("Ezreal", True), ("Teemo", False)] assert never_win(win_list1) == ["Teemo", "Yasuo"] assert never_win([('Ezreal', True), ('Yasuo', True), ('Jinx', False), ('Jinx', True)]) == [] def main(): test_least_exp_store() test_customer_loyalty() test_never_win() if __name__ == "__main__": main() # You will answer a question about collaboration in part 2.