<jupyter_start><jupyter_text>Exercises EOSC 211**Week 11 Day 1****Learning Objectives:**  1. Solve problems with python code2. Choose appropriate data structures to make your code neat and efficient  Question 1**A) You have a cash register with \\$20, \\$10, \\$5, \\$2, \\$1, \\$0.25, \\$0.10, \\$0.05 bills or coins. Write a program to make change – so that, for example, if someone gives you a \\$10 bill for something costing \\$6.55 the program will calculate that you get back \\$3.45 in change consisting of a \\$2, and \\$1, a \\$0.25, and 2 \\$0.10**  **You may find the floor division `//` and modulo ```%``` operators to be of use.****Store the denominations in a dictionary `denom={'twenties', 'tens', 'fives', 'toonies'...}`, The rest of the program is up to you. There are many correct ways to solve this problem**<jupyter_code>item_cost = 6.55  # dollars
cash_in = 10  # dollars
# your code here
# andrew's soln

# create a dictionary of bill names and values to loop over
money = {
    "twenties": 20,
    "tens": 10,
    "fives": 5,
    "toonies": 2,
    "loonies": 1,
    "quarters": 0.25,
    "dimes": 0.1,
    "nickels": 0.05,
}
denom = {}  # initialize an empty dictionary to put change into
change = cash_in - item_cost

for key in money.keys():
    denom[key] = change // money[key]  # add to denom dictionary
    change = change % money[key]  # get remaining chance owed

print(denom)<jupyter_output><empty_output><jupyter_text>**B) Turn this into a function called `getchange` that will take as input `item_cost`, `cash_in` and return `change`. Also, make your funtion raise an error if the customer does not give enough money to cover the cost of the purchase**<jupyter_code># your code here
# andrew's soln
def change(item_cost, cash_in):
    money = {
        "twenties": 20,
        "tens": 10,
        "fives": 5,
        "toonies": 2,
        "loonies": 1,
        "quarters": 0.25,
        "dimes": 0.1,
        "nickels": 0.05,
    }
    denom = {}  # initialize an empty dictionary to put change into
    change = cash_in - item_cost
    if change < 0:
        raise ValueError('not enough cash to cover item cost')

    for key in money.keys():
        denom[key] = change // money[key]  # add to denom dictionary
        change = change % money[key]  # get remaining chance owed

    return denom<jupyter_output><empty_output><jupyter_text>Question 2**A) For  `x1=[1, 7, -8, 2, -3, -9]`, what is contained in `y2` in each case after the code runs?  Do these three snippets of code do the same thing?  Show your work.**<jupyter_code>import numpy as np
x1 = np.array([1, 7, -8, 2, -3, -9])
y2 = []
for i in range(len(x1)):
    if x1[i] < 0:
        y2.append(x1[i])
print(y2)
y2 = x1
k = 0
for i in range(len(x1)):
    if x1[i] < 0:
        k = k + 1
        y2[k] = x1[i]
print(y2)<jupyter_output><empty_output><jupyter_text>not sure what the teachable is on this question... revisit later **B) Write code that produces the same result as A, but use vectorization instead of loops.**<jupyter_code># your code here
# andrew's soln
y2 = x1[x1 < 0]
print(y2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1330128205128205, 'fraction_numerical': 0.03717948717948718, 'mean_word_length': 3.2005383580080755, 'pattern_counts': {'":': 16, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '607824', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1060, 'n_words': 408, 'path': 'wk12/exercises.ipynb', 'repo_name': 'phaustin/eosc211_students', 'size': '3120'}