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
104 changes: 102 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,111 @@
"\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": 5,
"id": "136d8c68",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt\n",
"This product is available!\n",
"mug\n",
"This product is available!\n",
"hat\n",
"This product is available!\n",
"book\n",
"This product is available!\n",
"keychain\n",
"This product is available!\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"for product in products:\n",
" print (product)\n",
" print (\"This product is available!\")\n"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "2b64c916",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Producto agregado a la lista de compras.\n",
"Producto agregado a la lista de compras.\n",
"{'t-shirt', 'book'}\n"
]
}
],
"source": [
"lista_compras_cliente = set ()\n",
"producto = input (\"Producto que desea ordenar: \")\n",
"\n",
"while True:\n",
" if producto in products:\n",
" lista_compras_cliente.add (producto)\n",
" print (\"Producto agregado a la lista de compras.\")\n",
" else:\n",
" print (\"El producto no está disponible.\")\n",
" \n",
" continuar = input (\"¿Desea agregar otro producto? (si/no): \")\n",
" if continuar.lower() != 'si':\n",
" break\n",
" producto = input (\"Producto que desea ordenar: \")\n",
"\n",
"print (lista_compras_cliente)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "3fea43a6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"El producto t-shirt está en stock.\n",
"Cantidad disponible: 9\n",
"El producto book está en stock.\n",
"Cantidad disponible: 1\n"
]
}
],
"source": [
"inventory = {\n",
" \"t-shirt\": 10,\n",
" \"mug\": 5,\n",
" \"hat\": 0,\n",
" \"book\": 2,\n",
" \"keychain\": 15\n",
"}\n",
"for item in lista_compras_cliente:\n",
" if inventory[item] > 0:\n",
" print (f\"El producto {item} está en stock.\")\n",
" inventory[item] -= 1\n",
" print (f\"Cantidad disponible: {inventory[item]}\")\n",
" else:\n",
" print (f\"El producto {item} no está en stock.\") "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +155,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down