diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..8532bdf 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,116 @@ "\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": "5216e4e4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Products Ordered: {'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "customer_orders = set()\n", + "\n", + "while True:\n", + "\n", + " item = input(\"Enter the name of a product to order: \").strip().lower()\n", + " if item in products:\n", + " customer_orders.add(item)\n", + " else:\n", + " print(\"Invalid product. Choose from:\", products)\n", + " continue \n", + " \n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != (\"yes\"):\n", + " break\n", + "\n", + "print(\"\\nProducts_Ordered:\", customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "d8038d30", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid product. Choose from: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + "Products Ordered: {'book', 'mug', 'hat'}\n", + "Updated Inventory:\n", + "t-shirt: 21\n", + "mug: 33\n", + "hat: 45\n", + "book: 33\n", + "keychain: 54\n", + "\n", + "Products Ordered: {'book', 'mug', 'hat'}\n", + "Updated Inventory:\n", + "t-shirt: 21\n", + "mug: 32\n", + "hat: 45\n", + "book: 33\n", + "keychain: 54\n", + "\n", + "Products Ordered: {'book', 'mug', 'hat'}\n", + "Updated Inventory:\n", + "t-shirt: 21\n", + "mug: 32\n", + "hat: 44\n", + "book: 33\n", + "keychain: 54\n" + ] + } + ], + "source": [ + "\n", + "Products_Ordered: {'book', 'mug', 'hat'}\n", + "inventory={'t-shirt': 21, 'mug': 33, 'hat': 45, 'book': 34, 'keychain': 54}\n", + "while True:\n", + " item = input(\"Enter the name of a product to order: \").strip().lower()\n", + " if item in products:\n", + " customer_orders.add(item)\n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + " else:\n", + " print(\"Invalid product. Choose from:\", products)\n", + " for item in customer_orders:\n", + " \n", + " if inventory.get(item, 0) > 0:\n", + " inventory[item] -= 1\n", + "\n", + " print(\"\\nProducts Ordered:\", customer_orders)\n", + " print(\"Updated Inventory:\")\n", + " for p, qty in inventory.items():\n", + " print(f\"{p}: {qty}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2272ca0", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +160,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,