diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..09208e1 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,62 @@ "\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": null, + "id": "e13eaab3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n", + "\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)\").strip.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 product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -=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" }, @@ -55,7 +106,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,