automate-boring-stuff/exercises/ex08/ex08a.py

84 lines
2.0 KiB
Python

"""
Project: Sandwich Maker
Page 198
"""
import pyinputplus as pyip
prices, order, total = (
{
"bread": {
"wheat": 1.0,
"white": 0.9,
"sourdough": 1.1,
},
"protein": {
"chicken": 1.0,
"turkey": 1.1,
"ham": 0.9,
"tofu": 0.8,
},
"cheese": {
"cheddar": 0.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 * 0.16, 2)
total = round(subtotal + taxes, 2)
print(f"SUBTOTAL: {subtotal}")
print(f"TAXES: {taxes}")
print(f"TOTAL: {total}")