From 66051bf88a0ca804e843c94d1b3ef439a190dfd4 Mon Sep 17 00:00:00 2001 From: Juan Carlos Del Mar Lostanau <147656412+Juancarlosdelmarlostanau@users.noreply.github.com> Date: Tue, 15 Sep 2026 15:00:57 +0200 Subject: [PATCH 1/2] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 93 ++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 11 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..fca09f9 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -15,33 +15,104 @@ "id": "3851fcd1-cf98-4653-9c89-e003b7ec9400", "metadata": {}, "source": [ - "## Exercise: Managing Customer Orders Optimized\n", + "## Exercise: Optimized customer order management\n", "\n", - "In the last lab, you were starting an online store that sells various products. To ensure smooth operations, you developed a program that manages customer orders and inventory.\n", + "In the last lab, I was opening an online store that sells various products. To ensure smooth operations, it developed a program that manages customer orders and inventory.\n", "\n", - "You did so without using flow control. Let's go a step further and improve this code.\n", + "He did this without using flow control. Let's go one step further and improve this code.\n", "\n", "Follow the steps below to complete the exercise:\n", "\n", - "1. Look at your code from the lab data structures, and improve repeated code with loops.\n", + "1. Look at your code from the lab data structures and improve repeated code with loops.\n", "\n", - "2. Instead of asking the user to input the name of three products that a customer wants to order, do the following:\n", + "2. Instead of asking the user to enter the name of three products that a customer wants to order, do the following:\n", " \n", - " a. Prompt the user to enter the name of a product that a customer wants to order.\n", + " a. Prompt the user to enter the name of a product a customer wants to order.\n", " \n", " b. Add the product name to the \"customer_orders\" set.\n", " \n", - " c. Ask the user if they want to add another product (yes/no).\n", + " do. Ask the user if they want to add another product (yes/no).\n", " \n", - " d. Continue the loop until the user does not want to add another product.\n", + " d. Continue the cycle until the user does not wish to add another product.\n", "\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\")." + "3. Instead of updating inventory by subtracting 1 from the quantity of each product, do it only for the products that were ordered (those in \"customer_orders\")." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "9e26ac35", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "for p in products:\n", + " inventory[p] = int(input(f\"Cuantas unidades necesita de t-shirt?\"))\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "12d9cd05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "añadir_producto= \"yes\"\n", + "\n", + "while añadir_producto == \"yes\":\n", + " producto = input(\"ingrese una opcion de entre : t-shirt, mug, hat, book, or keychain\")\n", + " customer_orders.add(producto)\n", + " añadir_producto = input(\"quiere añadir otro producto? (yes/no):\").lower()\n", + " \n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "e46ead16", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 1, 'hat': 2, 'book': 4, 'keychain': 4}\n" + ] + } + ], + "source": [ + "for x in customer_orders:\n", + " if x in inventory:\n", + " inventory[x] -= 1\n", + "\n", + "print(inventory)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -55,7 +126,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4, From e8a5950540716ee9c32c3d427c93a477d33b0604 Mon Sep 17 00:00:00 2001 From: Juan Carlos Del Mar Lostanau <147656412+Juancarlosdelmarlostanau@users.noreply.github.com> Date: Tue, 15 Sep 2026 15:35:00 +0200 Subject: [PATCH 2/2] Update lab-python-flow-control.ipynb solucion 2 --- lab-python-flow-control.ipynb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index fca09f9..7c13fef 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -40,7 +40,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 22, "id": "9e26ac35", "metadata": {}, "outputs": [ @@ -56,14 +56,14 @@ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", "inventory = {}\n", "for p in products:\n", - " inventory[p] = int(input(f\"Cuantas unidades necesita de t-shirt?\"))\n", + " inventory[p] = int(input(f\"que cantidad de producto hay?\"))\n", "\n", "print(inventory)" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 23, "id": "12d9cd05", "metadata": {}, "outputs": [ @@ -71,16 +71,16 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'keychain', 'mug', 'hat'}\n" + "{'mug', 'hat', 'book'}\n" ] } ], "source": [ "customer_orders = set()\n", - "añadir_producto= \"yes\"\n", + "añadir_producto = \"yes\"\n", "\n", "while añadir_producto == \"yes\":\n", - " producto = input(\"ingrese una opcion de entre : t-shirt, mug, hat, book, or keychain\")\n", + " producto = input(\"ingrese una opcion de entre : t-shirt, mug, hat, book, or keychain\").lower()\n", " customer_orders.add(producto)\n", " añadir_producto = input(\"quiere añadir otro producto? (yes/no):\").lower()\n", " \n", @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 24, "id": "e46ead16", "metadata": {}, "outputs": [ @@ -97,16 +97,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': 1, 'mug': 1, 'hat': 2, 'book': 4, 'keychain': 4}\n" + "{'mug': 1, 'hat': 2, 'book': 3}\n" ] } ], "source": [ + "new_inventory = {}\n", + "\n", "for x in customer_orders:\n", " if x in inventory:\n", " inventory[x] -= 1\n", + " new_inventory[x] = inventory[x]\n", "\n", - "print(inventory)" + "\n", + "print(new_inventory)" ] } ],