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
54 changes: 52 additions & 2 deletions lab-python-flow-control.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,61 @@
"\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": 10,
"id": "e13eaab3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n",
"<class 'set'>\n",
"customer_orders are {'mug', 'hat'}\n",
"el inventario despues de quitar esos objetos queda {'t-shirt': 10, 'mug': 9, 'hat': 9, 'book': 10, 'keychain': 10}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"\"\"\" Le añado cantidades\"\"\"\n",
"for x in products:\n",
" cantidad = int(input(f\"Quantity of {x}\" ))\n",
" inventory[x] = cantidad\n",
"print(inventory)\n",
"\n",
"\"\"\" Creo las ordenes que voy a pedir hasta que me digan si o no\"\"\"\n",
"customer_orders = set()\n",
"print(type(customer_orders))\n",
"\n",
"another_product = \"yes\"\n",
"\n",
"while another_product == 'yes':\n",
" customer_orders.add (input(\"Escoge un producto para añadir\"))\n",
" another_product = input(\"Do you want to add another product (yes/no)\").lower()\n",
"\n",
"\"\"\" Imprimo las ordenes de cliente que van a pedir \"\"\"\n",
"print(f\"customer_orders are {customer_orders}\")\n",
"\n",
"\"\"\" Resto 1 cantidad solo a esas ordenes en el inventario\"\"\" # como es set solo me resta una de esas\n",
"\n",
"for x in customer_orders:\n",
" inventory[x] -=1\n",
"\n",
"\"\"\" Copruebo como ha cambiado el inventario\n",
"\"\"\"\n",
"print(f\"el inventario despues de quitar esos objetos queda {inventory}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -55,7 +105,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down