Skip to content
Open

lab #671

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
48 changes: 46 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,55 @@
"\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": "072c86a9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt'}\n",
"{'t-shirt': 9, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" inventory[product] = int(input(f\"Stock de {product}: \"))\n",
"\n",
"customer_orders = set()\n",
"\n",
"while True:\n",
" product = input(\"Producto que quiere el cliente: \").lower()\n",
"\n",
" if product in inventory:\n",
" customer_orders.add(product)\n",
" else:\n",
" print(\"Producto no válido.\")\n",
"\n",
" more = input(\"¿Añadir otro? (yes/no): \").lower()\n",
" if more == \"no\":\n",
" break\n",
"\n",
"for product in customer_orders:\n",
" if inventory[product] > 0:\n",
" inventory[product] -= 1\n",
"\n",
"print(customer_orders)\n",
"print(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +99,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down