From 989ad408597670625c119c2ec0b006595074a065 Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 15:08:20 +0100 Subject: [PATCH 1/2] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 98 ++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..babf886 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,105 @@ "\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": 29, + "id": "0f0dbd31", + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "customer_orders = set()\n", + "\n", + "inventory = {\"t-shirt\": 10, \"mug\" : 5, \"hat\": 2, \"book\": 0, \"keychain\": 15}\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc6c750a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Added hat to your order.\n", + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Added hat to your order.\n", + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "Added book to your order.\n", + "Your final order is: {'hat', 'book'} Thank you for shopping with us!\n", + "Sorry, hat is out of stock.\n", + "Sorry, book is out of stock.\n" + ] + } + ], + "source": [ + "while True:\n", + " print(\"Available products:\", products)\n", + " product = input(\"Enter the product you want to order:\")\n", + " \n", + "\n", + " if product in products:\n", + " customer_orders.add(product) \n", + " print(f\"Added {product} to your order.\")\n", + "\n", + " else:\n", + " print(\"Sorry, we don't have that product.\") \n", + " \n", + " continue_ordering = input(\"Do you want to order another product? (yes/no): \")\n", + " if continue_ordering.lower() != \"yes\":\n", + " break\n", + " \n", + "print(\"Your final order is:\", customer_orders, \"Thank you for shopping with us!\")\n", + "\n", + "for customer_order in customer_orders:\n", + " if inventory[customer_order] > 0:\n", + " inventory[customer_order] -= 1\n", + " print(\"{customer_order} is available. Remaining stock: {inventory[customer_order]}\")\n", + " else:\n", + " print(f\"Sorry, {customer_order} is out of stock.\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "f0f580e5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 10, 'mug': 5, 'hat': 0, 'book': 0, 'keychain': 15}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "409fcb47", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +149,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 63569f8c17ec5edbb53b88be7fbd8203f2142993 Mon Sep 17 00:00:00 2001 From: manufranso Date: Tue, 13 Jan 2026 15:10:38 +0100 Subject: [PATCH 2/2] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index babf886..266a9d2 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 1, "id": "0f0dbd31", "metadata": {}, "outputs": [], @@ -71,7 +71,7 @@ "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", "Added book to your order.\n", "Your final order is: {'hat', 'book'} Thank you for shopping with us!\n", - "Sorry, hat is out of stock.\n", + "{customer_order} is available. Remaining stock: {inventory[customer_order]}\n", "Sorry, book is out of stock.\n" ] } @@ -80,7 +80,7 @@ "while True:\n", " print(\"Available products:\", products)\n", " product = input(\"Enter the product you want to order:\")\n", - " \n", + " \n", "\n", " if product in products:\n", " customer_orders.add(product) \n", @@ -105,17 +105,25 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, + "id": "019781a1", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, "id": "f0f580e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'t-shirt': 10, 'mug': 5, 'hat': 0, 'book': 0, 'keychain': 15}" + "{'t-shirt': 10, 'mug': 5, 'hat': 1, 'book': 0, 'keychain': 15}" ] }, - "execution_count": 38, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" }