diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..afc7a2b 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,13 +37,178 @@ "\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": "markdown", + "id": "5e415177-de84-46ad-af4e-840e17551c22", + "metadata": {}, + "source": [ + "__Step 1:__" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b33b2db7-1c7f-4b8d-824e-504a4d82ff20", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter inventory quantity for t-shirt: 5\n", + "Enter inventory quantity for mug: 8\n", + "Enter inventory quantity for hat: 7\n", + "Enter inventory quantity for book: 9\n", + "Enter inventory quantity for keychain: 6\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " qty = int(input(f\"Enter inventory quantity for {product}: \"))\n", + " inventory[product] = qty\n", + "\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "markdown", + "id": "ae9cc25b-5ee5-4002-acbf-33abb12cef0c", + "metadata": {}, + "source": [ + "__Step 2:__" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "fbb10fe9-29d7-4208-8847-9533bc9be6f9", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of a product to order (['t-shirt', 'mug', 'hat', 'book', 'keychain']): hat\n", + "Add another product? (yes/no): yes\n", + "Enter the name of a product to order (['t-shirt', 'mug', 'hat', 'book', 'keychain']): mug\n", + "Add another product? (yes/no): no\n" + ] + } + ], + "source": [ + "while True:\n", + " product = input(f\"Enter the name of a product to order ({products}): \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not found. Please enter a valid product name.\")\n", + " continue\n", + " \n", + " # Ask if the user wants to add another product\n", + " another = input(\"Add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "983affa7-7431-4f40-8f82-0aa1a54f0750", + "metadata": {}, + "outputs": [], + "source": [ + "while True:\n", + " product = input(f\"Enter the name of a product to order ({products}): \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product not found. Please enter a valid product name.\")\n", + " continue\n", + " \n", + " # Ask if the user wants to add another product\n", + " another = input(\"Add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break" + ] + }, + { + "cell_type": "markdown", + "id": "570e38c5-6537-446b-99f1-04fb53292732", + "metadata": {}, + "source": [ + "__Step 3:__" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "31a7fb30-e4bd-4cf2-afa0-01f45a0ea134", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Products ordered by customer: {'hat', 'mug', 'book'}\n", + "\n", + "Updated Inventory after orders:\n", + "t-shirt: 5\n", + "mug: 6\n", + "hat: 5\n", + "book: 7\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " else:\n", + " print(f\"Warning: {product} is out of stock and can't be ordered.\")\n", + "\n", + "print(\"\\nProducts ordered by customer:\", customer_orders)\n", + "print(\"\\nUpdated Inventory after orders:\")\n", + "for product in products:\n", + " print(f\"{product}: {inventory[product]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d70a59c-6424-4adf-b48f-12ff2729e05f", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47b422bb-e742-48b3-beab-5ec3a27155ce", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6eea31a1-68f1-4ce0-9a59-86df62c3a4cf", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironhack", "language": "python", - "name": "python3" + "name": "ironhack" }, "language_info": { "codemirror_mode": { @@ -55,7 +220,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" } }, "nbformat": 4,