Ejercicio 8a

This commit is contained in:
perro tuerto 2023-04-17 13:37:04 -07:00
parent 2984790c53
commit f8112e53a4
3 changed files with 48 additions and 0 deletions

47
exercises/ex08/ex08a.py Normal file
View File

@ -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}")

0
exercises/ex08/ex08b.py Normal file
View File

View File

@ -0,0 +1 @@
pyinputplus