diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..78ac785 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,6 +43,83 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3588f6d6", + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " \n", + " while True:\n", + " product = input(\"Enter a product name: \").lower()\n", + " \n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not available. Please choose from the list.\")\n", + " continue\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").lower()\n", + " if another != \"yes\":\n", + " break\n", + " \n", + " return customer_orders\n", + "\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory\n", + "\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_unique_orders = len(customer_orders)\n", + " percentage_unique_orders = (total_unique_orders / len(products)) * 100\n", + " return total_unique_orders, percentage_unique_orders\n", + "\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(f\"Total unique products ordered: {total}\")\n", + " print(f\"Percentage of unique products ordered: {percentage:.2f}%\")\n", + "\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"Updated inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", + "\n", + "\n", + "# --- Ejecución ---\n", + "inventory = initialize_inventory(products)\n", + "customer_orders = get_customer_orders()\n", + "inventory = update_inventory(customer_orders, inventory)\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "print(\"Customer orders:\", customer_orders)\n", + "print_updated_inventory(inventory)" + ] } ], "metadata": {