diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..4550b8a 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,99 @@ "\n", "3. Instead of updating the inventory by subtracting 1 from the quantity of each product, only do it for the products that were ordered (those in \"customer_orders\")." ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "7cc6e512", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the quantity available for each product:\n", + "\n", + "Products ordered by the customer: {'hat'}\n", + "\n", + "Order Statistics:\n", + "Total Products Ordered: 1\n", + "Percentage of Products Ordered: 20.00%\n", + "\n", + "Updated Inventory:\n", + "t-shirt: 2\n", + "mug: 1\n", + "hat: 0\n", + "book: 1\n", + "keychain: 1\n" + ] + } + ], + "source": [ + "# Lista de productos disponibles\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Crear inventario vacĂ­o\n", + "inventory = {}\n", + "\n", + "# Pedir al usuario la cantidad disponible de cada producto\n", + "print(\"Enter the quantity available for each product:\")\n", + "for product in products:\n", + " while True:\n", + " try:\n", + " quantity = int(input(f\"{product}: \"))\n", + " if quantity < 0:\n", + " print(\"Please enter a non-negative number.\")\n", + " continue\n", + " inventory[product] = quantity\n", + " break\n", + " except ValueError:\n", + " print(\"Please enter a valid integer.\")\n", + "\n", + "# Crear set de pedidos del cliente\n", + "customer_orders = set()\n", + "\n", + "# Pedir al usuario productos hasta que diga 'no'\n", + "while True:\n", + " product_ordered = input(\"Enter a product the customer wants to order: \").strip()\n", + " if product_ordered not in products:\n", + " print(\"Product not available. Please choose from:\", products)\n", + " continue\n", + " customer_orders.add(product_ordered)\n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != 'yes':\n", + " break\n", + "\n", + "# Mostrar productos pedidos\n", + "print(\"\\nProducts ordered by the customer:\", customer_orders)\n", + "\n", + "# EstadĂ­sticas del pedido\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "# Actualizar inventario solo de los productos pedidos\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"Warning: {product} is out of stock!\")\n", + "\n", + "# Mostrar inventario actualizado\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, qty in inventory.items():\n", + " print(f\"{product}: {qty}\")\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.9" } }, "nbformat": 4,