altervisi0n

Untitled

Sep 28th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.80 KB | None | 0 0
  1. bouquets = {
  2.     'Романтика': {
  3.         'состав': ['розы', 'гипсофила'],
  4.         'цена': 2500,
  5.         'количество': 15
  6.     },
  7.     'Нежность': {
  8.         'состав': ['лилии', 'эустома'],
  9.         'цена': 2200,
  10.         'количество': 10
  11.     },
  12.     'Страсть': {
  13.         'состав': ['красные розы', 'берграс'],
  14.         'цена': 3100,
  15.         'количество': 8
  16.     }
  17. }
  18.  
  19.  
  20. def view_description():
  21.     for name, details in bouquets.items():
  22.         print(f"{name}: состоит из {', '.join(details['состав'])}")
  23.  
  24.  
  25. def view_price():
  26.     for name, details in bouquets.items():
  27.         print(f"{name}: {details['цена']} руб.")
  28.  
  29.  
  30. def view_quantity():
  31.     for name, details in bouquets.items():
  32.         print(f"{name}: в наличии {details['количество']} шт.")
  33.  
  34.  
  35. def view_all():
  36.     for name, details in bouquets.items():
  37.         print(f"--- {name} ---\n"
  38.               f"  Состав: {', '.join(details['состав'])}\n"
  39.               f"  Цена: {details['цена']} руб.\n"
  40.               f"  В наличии: {details['количество']} шт.\n")
  41.  
  42.  
  43. def purchase():
  44.     total_price = 0
  45.     while True:
  46.         bouquet_name = input("Введите название букета для покупки (или 'n' для выхода): ")
  47.         if bouquet_name.lower() == 'n':
  48.             break
  49.  
  50.         if bouquet_name not in bouquets:
  51.             print("Такого букета нет в наличии.")
  52.             continue
  53.  
  54.         try:
  55.             quantity = int(input(f"Сколько букетов '{bouquet_name}' вы хотите купить? "))
  56.             if quantity <= 0:
  57.                 print("Количество должно быть положительным.")
  58.                 continue
  59.  
  60.             if bouquets[bouquet_name]['количество'] >= quantity:
  61.                 bouquets[bouquet_name]['количество'] -= quantity
  62.                 current_purchase_price = bouquets[bouquet_name]['цена'] * quantity
  63.                 total_price += current_purchase_price
  64.                 print(f"Вы купили {quantity} шт. '{bouquet_name}'. "
  65.                       f"Сумма: {current_purchase_price} руб. "
  66.                       f"Осталось: {bouquets[bouquet_name]['количество']} шт.")
  67.             else:
  68.                 print(f"Недостаточно букетов. В наличии только {bouquets[bouquet_name]['количество']} шт.")
  69.  
  70.         except ValueError:
  71.             print("Пожалуйста, введите корректное число.")
  72.  
  73.     print(f"\nОбщая сумма вашей покупки: {total_price} руб.")
  74.  
  75.  
  76. def main():
  77.     while True:
  78.         print("\n--- Меню цветочного магазина ---")
  79.         print("1. Просмотр описания букетов")
  80.         print("2. Просмотр цен")
  81.         print("3. Просмотр количества")
  82.         print("4. Показать всю информацию")
  83.         print("5. Совершить покупку")
  84.         print("6. Выход")
  85.  
  86.         choice = input("Выберите пункт меню: ")
  87.  
  88.         if choice == '1':
  89.             view_description()
  90.         elif choice == '2':
  91.             view_price()
  92.         elif choice == '3':
  93.             view_quantity()
  94.         elif choice == '4':
  95.             view_all()
  96.         elif choice == '5':
  97.             purchase()
  98.         elif choice == '6':
  99.             print("До свидания! Приходите еще!")
  100.             break
  101.         else:
  102.             print("Неверный пункт меню. Попробуйте снова.")
  103.  
  104.  
  105. main()
Advertisement
Add Comment
Please, Sign In to add comment