47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
goods = {
|
||
"пицца": 250,
|
||
"роллы": 300,
|
||
"чипсы": 100,
|
||
"чай": 50,
|
||
}
|
||
|
||
menu = [*zip(range(1, len(goods) + 1), *zip(*goods.items()))]
|
||
selection = {i: name for i, name, *_ in menu}
|
||
cart = {}
|
||
|
||
|
||
def show_menu():
|
||
print("Меню:")
|
||
for i, name, price in menu:
|
||
print(f"{i} - {name} {price} руб.")
|
||
print(f"{menu[-1][0] + 1} - выход\n")
|
||
|
||
|
||
def show_cart():
|
||
print("Ваша корзина:")
|
||
total = 0
|
||
for name, count in cart.items():
|
||
pos_sum = goods[name] * count
|
||
print(f"{name} - {count} шт. - {pos_sum} руб.")
|
||
total += pos_sum
|
||
print(" - - - - - - ")
|
||
print(f"Итого: {total} руб.\n")
|
||
|
||
|
||
def ask_user():
|
||
show_menu()
|
||
i = int(input("Ваш выбор: "))
|
||
while not 0 < i <= len(menu) + 1:
|
||
show_menu()
|
||
i = int(input("Ваш выбор: "))
|
||
if i <= len(menu):
|
||
return selection[i]
|
||
|
||
|
||
print("Добро пожаловать в сервис заказа еды")
|
||
for name in iter(ask_user, None):
|
||
cart.setdefault(name, 0)
|
||
cart[name] += 1
|
||
print()
|
||
show_cart()
|