Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,75 @@
"\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": "34fde8a6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 't-shirt', 'mug'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"t-shirt: 8\n",
"mug: 7\n",
"hat: 6\n",
"book: 6\n",
"keychain: 5\n"
]
}
],
"source": [
"# Paso 1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"# Paso 2\n",
"inventory = {}\n",
"\n",
"# Paso 3\n",
"for product in products:\n",
" inventory[product] = int(input(f\"Introduce la cantidad de {product}: \"))\n",
"\n",
"# Paso 4\n",
"customer_orders = set()\n",
"\n",
"# Paso 5\n",
"answer = \"yes\"\n",
"while answer == \"yes\":\n",
" product = input(\"Introduce el nombre del producto: \").strip().lower()\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"Producto no válido, inténtalo de nuevo por favor\")\n",
" answer = input(\"¿Quieres añadir otro producto? (yes/no): \").lower()\n",
"\n",
"# Paso 6\n",
"print(customer_orders)\n",
"\n",
"# Paso 7 y 8\n",
"total_products_ordered = len(customer_orders)\n",
"percentage = (len(customer_orders) / len(products)) * 100\n",
"order_status = (total_products_ordered, percentage)\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"# Paso 9 y 10\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"for product in inventory:\n",
" print(f\"{product}: {inventory[product]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down