diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..e0606b7 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,6 +37,152 @@ "\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": 3, + "id": "4b36a05d-191d-4933-9171-9392e51184d3", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter name of product to order: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 1 hat to your order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Add another product? (yes/no): mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Products ordered: ['hat']\n", + "update inventory: {'t-shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "update_inventory = {product: 5 for product in products}\n", + "\n", + "customer_orders = []\n", + "\n", + "condition = True\n", + "\n", + "while condition:\n", + " product = input(\"Enter name of product to order: \").lower()\n", + " if product not in products:\n", + " print(\"No product available.\")\n", + " else:\n", + " if inventory[product] == 0:\n", + " print(f\"Out of stock.\")\n", + " else:\n", + " customer_orders.append(product)\n", + " inventory[product] -= 1\n", + " print(f\"Added 1 {product} to your order.\")\n", + " \n", + " more = input(\"Add another product? (yes/no): \").lower()\n", + " if more != \"yes\":\n", + " condition = False\n", + "\n", + "print(\"Products ordered: \", customer_orders)\n", + "print(\"update inventory:\", update_inventory)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2cb2a6c5-a277-402a-8c9f-418328ae9097", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4587f20e-eb71-463b-a6dd-10f47d0b37dc", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter name of product to order: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 1 hat to your order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Add another product? (yes/no): hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Products ordered: ['hat']\n", + "update inventory: {'t-shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "update_inventory = {product: 5 for product in products}\n", + "\n", + "customer_orders = []\n", + "\n", + "while True:\n", + " product = input(\"Enter name of product to order: \").lower()\n", + " \n", + " if product not in products:\n", + " print(\"No product available.\")\n", + " else:\n", + " if inventory[product] == 0:\n", + " print(f\"Out of stock.\")\n", + " else:\n", + " customer_orders.append(product)\n", + " inventory[product] -= 1\n", + " print(f\"Added 1 {product} to your order.\")\n", + " \n", + " more = input(\"Add another product? (yes/no): \").lower()\n", + " if more != \"yes\":\n", + " break\n", + "\n", + "print(\"Products ordered: \", customer_orders)\n", + "print(\"update inventory:\", update_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0bf5c94-47e4-490f-9ec1-a007faa73a07", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -55,7 +201,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,