diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..989bc61 Binary files /dev/null and b/.DS_Store differ diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..08ca3b2 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,13 +37,140 @@ "\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": "79c43b72-3720-4138-8d35-ea62836c49c9", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "inventory = {\n", + " \"t-shirt\": 10,\n", + " \"mug\": 15,\n", + " \"hat\": 8,\n", + " \"book\": 5,\n", + " \"keychain\": 20\n", + "}\n", + "\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2be6001d-7c0e-4fb9-92a5-d0ba56ec0de6", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a product a customer wants to order: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "hat added to the order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Add another product? (yes/no): yes\n", + "Enter a product a customer wants to order: mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mug added to the order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Add another product? (yes/no): no\n" + ] + } + ], + "source": [ + "while True:\n", + " product = input(\"Enter a product a customer wants to order: \").lower()\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " print(product, \"added to the order.\")\n", + " else:\n", + " print(\"Product not available.\")\n", + "\n", + " another = input(\"Add another product? (yes/no): \").lower()\n", + "\n", + " if another == \"no\":\n", + " break" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "949e68af-dcf6-40a5-925a-e1d38e01286b", + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_orders:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "67f00737-13fc-4c9c-9aea-774e43fce5a5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer orders: {'hat', 'mug'}\n", + "\n", + "Updated inventory:\n", + "t-shirt : 10\n", + "mug : 14\n", + "hat : 7\n", + "book : 5\n", + "keychain : 20\n" + ] + } + ], + "source": [ + "print(\"Customer orders:\", customer_orders)\n", + "\n", + "print(\"\\nUpdated inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15cf667a-781f-49ba-8460-e84f2eb663fc", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -55,7 +182,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,