diff --git a/exercises/ex08/ex08a.py b/exercises/ex08/ex08a.py new file mode 100644 index 0000000..e3c6e33 --- /dev/null +++ b/exercises/ex08/ex08a.py @@ -0,0 +1,47 @@ +import pyinputplus as pyip + +prices, order, total = { + "bread": { "wheat": 1.0, "white": .9, "sourdough": 1.1, }, + "protein": { "chicken": 1.0, "turkey": 1.1, "ham": .9, "tofu": .8, }, + "cheese": { "cheddar": .9, "swiss": 1.0, "mozzarella.": 1.1, } +}, {}, 0 + +def add(key, ismenu=False): + isadd = pyip.inputYesNo(prompt=f"Do you want {key}? [y/n]\n") == "yes" + if isadd and ismenu: + return pyip.inputMenu(list(prices[key].keys()), numbered=True, prompt=f"Please, select {key}:\n") + elif isadd: + return True + else: + return False + + +order["bread"] = pyip.inputMenu(list(prices["bread"].keys()), numbered=True, prompt="Please, select bread:\n") +order["protein"] = pyip.inputMenu(list(prices["protein"].keys()), numbered=True, prompt="Please, select protein:\n") +order["cheese"] = add("cheese", True) +order["mayo"] = add("mayo") +order["mustard"] = add("mustard") +order["lettuce"] = add("lettuce") +order["tomato"] = add("tomato") +order["quantity"] = pyip.inputInt(prompt="How many sandwiches? [number]:\n", greaterThan=0) + +sandwich = "sandwich" if order["quantity"] == 1 else "sandwiches" +print(f"Your order\n{order['quantity']} {sandwich} with:") +for key in order.keys(): + prompt = " " + if type(order[key]) == str: + price = prices[key][order[key]] + total += price + print(f"{prompt}{order[key]}: {price}") + elif type(order[key]) == bool: + if order[key]: + print(f"{prompt}{key}: 0.0") + else: + print(f"{prompt}NO {key}") +subtotal = round(total * order["quantity"], 2) +taxes = round(subtotal * .16, 2) +total = round(subtotal + taxes, 2) +print(f"SUBTOTAL: {subtotal}") +print(f"TAXES: {taxes}") +print(f"TOTAL: {total}") + diff --git a/exercises/ex08/ex08b.py b/exercises/ex08/ex08b.py new file mode 100644 index 0000000..e69de29 diff --git a/exercises/ex08/requirements.txt b/exercises/ex08/requirements.txt new file mode 100644 index 0000000..e998ed2 --- /dev/null +++ b/exercises/ex08/requirements.txt @@ -0,0 +1 @@ +pyinputplus