From 0edfc81f7fcc2559f2fedf5b929dc495a75d4278 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Fri, 17 Apr 2026 18:07:22 +0200 Subject: [PATCH 1/3] Update lab-python-flow-control.ipynb respuesta flow control --- lab-python-flow-control.ipynb | 149 +++++++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index f4c7391..534876f 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -37,11 +37,156 @@ "\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": 1, + "id": "2e4cfd1f", + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "be2e6f46", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- Setup inventory -\n" + ] + } + ], + "source": [ + "print(\"- Setup inventory -\")\n", + "for item in products:\n", + " quantity= int(input(f\"Add the inventory for {item} items, please: \"))\n", + " inventory[item] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "99571e12", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "- Place Your Orders -)\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "print(\"\\n- Place Your Orders -)\")\n", + "for i in range (3):\n", + " choice = input(f\"Write the name of the product {i+1}: \")\n", + " customer_orders.add(choice)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "2a8dbfd4", + "metadata": {}, + "outputs": [], + "source": [ + "total_inventory_items = len(products)\n", + "total_orders = len(customer_orders)\n", + "percentage = (total_orders / total_inventory_items) * 100\n", + "order_status = (total_orders, percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "1f24bd4d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Order Statistics ---\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "print(\"\\n--- Order Statistics ---\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "bfa0b94d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Updating Inventory ---\n", + "Inventory updated: book now has 5 units.\n", + "Inventory updated: hat now has 6 units.\n", + "Inventory updated: mug now has 7 units.\n" + ] + } + ], + "source": [ + "print(\"\\n--- Updating Inventory ---\")\n", + "for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " print(f\"Inventory updated: {product} now has {inventory[product]} units.\")\n", + " else:\n", + " print(f\"Product '{product}' not found in original inventory.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "82031867", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "--- Final Inventory Status ---\n", + "Product: t-shirt | Remaining: 9\n", + "Product: mug | Remaining: 7\n", + "Product: hat | Remaining: 6\n", + "Product: book | Remaining: 5\n", + "Product: keychain | Remaining: 5\n" + ] + } + ], + "source": [ + "print(\"\\n--- Final Inventory Status ---\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"Product: {product:10} | Remaining: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -55,7 +200,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4, From 577bc9697aea4ddc93e9cd4a4315ff9ac7576a02 Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Tue, 21 Apr 2026 16:12:46 +0200 Subject: [PATCH 2/3] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 39 +++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 534876f..2644051 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "99571e12", "metadata": {}, "outputs": [ @@ -81,21 +81,24 @@ "output_type": "stream", "text": [ "\n", - "- Place Your Orders -)\n" + "- Place Your Orders -\n" ] } ], "source": [ "customer_orders = set()\n", - "print(\"\\n- Place Your Orders -)\")\n", - "for i in range (3):\n", - " choice = input(f\"Write the name of the product {i+1}: \")\n", - " customer_orders.add(choice)" + "print(\"\\n- Place Your Orders -\")\n", + "while True:\n", + " choice = input(f\"Write the name of the product you want to order: \").strip().lower()\n", + " customer_orders.add(choice)\n", + " another= input(\"Do you want to add another product?(yes/no): \").strip().lower()\n", + " if another != \"yes\":\n", + " break" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "id": "2a8dbfd4", "metadata": {}, "outputs": [], @@ -108,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "id": "1f24bd4d", "metadata": {}, "outputs": [ @@ -131,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "id": "bfa0b94d", "metadata": {}, "outputs": [ @@ -159,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "82031867", "metadata": {}, "outputs": [ @@ -169,24 +172,24 @@ "text": [ "\n", "--- Final Inventory Status ---\n", - "Product: t-shirt | Remaining: 9\n", - "Product: mug | Remaining: 7\n", - "Product: hat | Remaining: 6\n", - "Product: book | Remaining: 5\n", - "Product: keychain | Remaining: 5\n" + "Product: t-shirt , Remaining: 9\n", + "Product: mug , Remaining: 7\n", + "Product: hat , Remaining: 6\n", + "Product: book , Remaining: 5\n", + "Product: keychain , Remaining: 5\n" ] } ], "source": [ "print(\"\\n--- Final Inventory Status ---\")\n", "for product, quantity in inventory.items():\n", - " print(f\"Product: {product:10} | Remaining: {quantity}\")" + " print(f\"Product: {product:10}, Remaining: {quantity}\")" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -200,7 +203,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.14.4" + "version": "3.13.9" } }, "nbformat": 4, From feb6a78d945af4b199f2835833246d5d4afc355b Mon Sep 17 00:00:00 2001 From: "ERIKA J. DIAZ DAFT ABR2026" Date: Wed, 29 Apr 2026 10:06:32 +0200 Subject: [PATCH 3/3] Update lab-python-flow-control.ipynb --- lab-python-flow-control.ipynb | 176 +++++++++------------------------- 1 file changed, 46 insertions(+), 130 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 2644051..eca498b 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -41,149 +41,65 @@ { "cell_type": "code", "execution_count": 1, - "id": "2e4cfd1f", - "metadata": {}, - "outputs": [], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "inventory = {}" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "be2e6f46", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "- Setup inventory -\n" - ] - } - ], - "source": [ - "print(\"- Setup inventory -\")\n", - "for item in products:\n", - " quantity= int(input(f\"Add the inventory for {item} items, please: \"))\n", - " inventory[item] = quantity" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "99571e12", + "id": "34fde8a6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n", - "- Place Your Orders -\n" - ] - } - ], - "source": [ - "customer_orders = set()\n", - "print(\"\\n- Place Your Orders -\")\n", - "while True:\n", - " choice = input(f\"Write the name of the product you want to order: \").strip().lower()\n", - " customer_orders.add(choice)\n", - " another= input(\"Do you want to add another product?(yes/no): \").strip().lower()\n", - " if another != \"yes\":\n", - " break" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "2a8dbfd4", - "metadata": {}, - "outputs": [], - "source": [ - "total_inventory_items = len(products)\n", - "total_orders = len(customer_orders)\n", - "percentage = (total_orders / total_inventory_items) * 100\n", - "order_status = (total_orders, percentage)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "1f24bd4d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "--- Order Statistics ---\n", + "{'hat', 't-shirt', 'mug'}\n", + "Order Statistics:\n", "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 60.00%\n" + "Percentage of Products Ordered: 60.0%\n", + "t-shirt: 8\n", + "mug: 7\n", + "hat: 6\n", + "book: 6\n", + "keychain: 5\n" ] } ], "source": [ - "print(\"\\n--- Order Statistics ---\")\n", + "# Paso 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# Paso 2\n", + "inventory = {}\n", + "\n", + "# Paso 3\n", + "for product in products:\n", + " inventory[product] = int(input(f\"Introduce la cantidad de {product}: \"))\n", + "\n", + "# Paso 4\n", + "customer_orders = set()\n", + "\n", + "# Paso 5\n", + "answer = \"yes\"\n", + "while answer == \"yes\":\n", + " product = input(\"Introduce el nombre del producto: \").strip().lower()\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Producto no válido, inténtalo de nuevo por favor\")\n", + " answer = input(\"¿Quieres añadir otro producto? (yes/no): \").lower()\n", + "\n", + "# Paso 6\n", + "print(customer_orders)\n", + "\n", + "# Paso 7 y 8\n", + "total_products_ordered = len(customer_orders)\n", + "percentage = (len(customer_orders) / len(products)) * 100\n", + "order_status = (total_products_ordered, percentage)\n", + "print(\"Order Statistics:\")\n", "print(f\"Total Products Ordered: {order_status[0]}\")\n", - "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "bfa0b94d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "--- Updating Inventory ---\n", - "Inventory updated: book now has 5 units.\n", - "Inventory updated: hat now has 6 units.\n", - "Inventory updated: mug now has 7 units.\n" - ] - } - ], - "source": [ - "print(\"\\n--- Updating Inventory ---\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n", + "\n", + "# Paso 9 y 10\n", "for product in customer_orders:\n", - " if product in inventory:\n", - " inventory[product] -= 1\n", - " print(f\"Inventory updated: {product} now has {inventory[product]} units.\")\n", - " else:\n", - " print(f\"Product '{product}' not found in original inventory.\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "82031867", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "--- Final Inventory Status ---\n", - "Product: t-shirt , Remaining: 9\n", - "Product: mug , Remaining: 7\n", - "Product: hat , Remaining: 6\n", - "Product: book , Remaining: 5\n", - "Product: keychain , Remaining: 5\n" - ] - } - ], - "source": [ - "print(\"\\n--- Final Inventory Status ---\")\n", - "for product, quantity in inventory.items():\n", - " print(f\"Product: {product:10}, Remaining: {quantity}\")" + " inventory[product] -= 1\n", + "for product in inventory:\n", + " print(f\"{product}: {inventory[product]}\")" ] } ],