diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..5f006f1 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,78 @@ "\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": "25c61935", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Customer Orders:\n", + "{'mug', 't-shirt', 'hat'}\n", + "\n", + "Updated Inventory:\n", + "{'t-shirt': 9, 'mug': 4, 'hat': 7, 'hoodie': 3}\n" + ] + } + ], + "source": [ + "# Initial inventory (example from previous lab)\n", + "inventory = {\n", + " \"t-shirt\": 10,\n", + " \"mug\": 5,\n", + " \"hat\": 8,\n", + " \"hoodie\": 3\n", + "}\n", + "\n", + "# Set to store customer orders\n", + "customer_orders = set()\n", + "\n", + "# Step 2: Ask user for products using a loop\n", + "while True:\n", + " product = input(\"Enter the name of the product you want to order: \").strip().lower()\n", + " customer_orders.add(product)\n", + "\n", + " another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break\n", + "\n", + "# Step 3: Update inventory only for ordered products\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + "\n", + "# Output results\n", + "print(\"\\nCustomer Orders:\")\n", + "print(customer_orders)\n", + "\n", + "print(\"\\nUpdated Inventory:\")\n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a555dce3", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "id": "0bbd901d", + "metadata": {}, + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +122,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,