diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..80a4c13 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,13 +37,129 @@ "\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": "38f15044-1a13-49ce-859c-2a0ec61f346c", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter the quantity of t-shirt in the inventory 10\n", + "Please enter the quantity of mug in the inventory 10\n", + "Please enter the quantity of hat in the inventory 10\n", + "Please enter the quantity of book in the inventory 20\n", + "Please enter the quantity of keychain in the inventory 26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 20, 'keychain': 26}\n", + "Starting Order\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of a product to order (or type 'done' to finish): mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'mug' added to your order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Do you want to add another product? (yes/no): done\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Complete\n", + "Products ordered: {'mug'}\n", + "\n", + "Updating Inventory\n", + "Inventory before update: {'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 20, 'keychain': 26}\n", + "Updated quantity for 'mug'. New stock: 9\n", + "\n", + "Inventory after update: {'t-shirt': 10, 'mug': 9, 'hat': 10, 'book': 20, 'keychain': 26}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " inventory_volume = input(f\"Please enter the quantity of {product} in the inventory\")\n", + " inventory_volume = int(inventory_volume)\n", + " inventory[product] = inventory_volume\n", + "print(inventory)\n", + "\n", + "customer_orders = set()\n", + "\n", + "print(\"Starting Order\")\n", + "\n", + "\n", + "while True:\n", + " product_name = input(\"Enter the name of a product to order (or type 'done' to finish): \").strip()\n", + " \n", + " if product_name.lower() == 'done':\n", + " break\n", + " \n", + " if product_name in inventory:\n", + " customer_orders.add(product_name)\n", + " print(f\"'{product_name}' added to your order.\")\n", + " else:\n", + " print(f\"'{product_name}' is not a valid product in our inventory. Please try again.\")\n", + " continue \n", + "\n", + " add_another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + "\n", + " if add_another != 'yes':\n", + " break \n", + "\n", + "print(\"Order Complete\")\n", + "print(f\"Products ordered: {customer_orders}\")\n", + "\n", + "print(\"\\nUpdating Inventory\")\n", + "print(f\"Inventory before update: {inventory}\")\n", + "\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " print(f\"Updated quantity for '{product}'. New stock: {inventory[product]}\")\n", + "\n", + "print(f\"\\nInventory after update: {inventory}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2b47da2-64d8-4915-9011-8250bb34a5f8", + "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 +171,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,