From f9dd34447ab6c52f8ebd181e7069cf42e052a685 Mon Sep 17 00:00:00 2001 From: bperezlovisolo Date: Tue, 13 Jan 2026 14:55:48 +0100 Subject: [PATCH 1/3] lab flow control lab flow control --- lab-python-flow-control.ipynb | 92 ++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..7e808e6 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,99 @@ "\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": 2, + "id": "fefa9890", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b370f26", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "inventory = {}\n", + "for product in products:\n", + " inventory[product] = int(input(\"Enter the quantity of the product: \"))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "ba3165d1", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()\n", + "\n", + "for customer_order in products:\n", + " customer_order = input(\"Which product would you like to order? \")\n", + " customer_orders.add(customer_order)\n", + "\n", + " extra_orders = input(\"Would you like to order another product? (yes/no) \").lower()\n", + " if extra_orders != 'yes':\n", + " break\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "466f8d26", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "8d848302", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': -1, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "if customer_order in customer_orders:\n", + " inventory[customer_order] -= 1\n", + " print(inventory)\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +143,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4, From fa817c7780198d49c17bc821e3f0d4b229715333 Mon Sep 17 00:00:00 2001 From: bperezlovisolo Date: Tue, 13 Jan 2026 15:08:35 +0100 Subject: [PATCH 2/3] lab flow control --- lab-python-flow-control.ipynb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 7e808e6..fd5e1db 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -108,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "id": "8d848302", "metadata": {}, "outputs": [ @@ -123,7 +123,8 @@ "source": [ "if customer_order in customer_orders:\n", " inventory[customer_order] -= 1\n", - " print(inventory)\n" + " print(inventory)\n", + "#prueba" ] } ], From 60bfef463e475dad90c78b4f321ab398539ccde1 Mon Sep 17 00:00:00 2001 From: bperezlovisolo Date: Tue, 13 Jan 2026 15:19:00 +0100 Subject: [PATCH 3/3] lab flow control --- lab-python-flow-control.ipynb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index fd5e1db..e8c6a13 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -108,24 +108,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "8d848302", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 1, 'mug': -1, 'hat': 3, 'book': 4, 'keychain': 5}\n" - ] - } - ], + "outputs": [], "source": [ - "if customer_order in customer_orders:\n", - " inventory[customer_order] -= 1\n", - " print(inventory)\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", "#prueba" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7af7cfc7", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {