diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..283050f 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -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" }, @@ -55,7 +99,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4,