From 3d445de0e007346721d3608bc72f8de11ac526f9 Mon Sep 17 00:00:00 2001 From: Javier Soto Date: Mon, 6 Oct 2025 18:41:31 +0200 Subject: [PATCH 1/2] Update lab-python-data-structures.ipynb Lab 1 Terminado --- lab-python-data-structures.ipynb | 263 ++++++++++++++++++++++++++++++- 1 file changed, 261 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..fcf8265d 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,270 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Create an empty dictionary called `inventory`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory:\n", + "{'t-shirt': 5, 'mug': 10, 'hat': 7, 'book': 4, 'keychain': 2}\n" + ] + } + ], + "source": [ + "valor_tshirt = int(input(f\"Enter the quantity of t-shirts avaliable: \"))\n", + "valor_mug = int(input(f\"Enter the quantity of mug avaliable: \"))\n", + "valor_hat = int(input(f\"Enter the quantity of hat avaliable: \"))\n", + "valor_book = int(input(f\"Enter the quantity of book avaliable: \"))\n", + "valor_keychain = int(input(f\"Enter the quantity of keychain avaliable: \"))\n", + "\n", + "\n", + "inventory = {\n", + " \"t-shirt\" : valor_tshirt,\n", + " \"mug\" : valor_mug,\n", + " \"hat\" : valor_hat,\n", + " \"book\" : valor_book,\n", + " \"keychain\" : valor_keychain\n", + "}\n", + "\n", + "print (\"Inventory:\")\n", + "print (inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Create an empty set called `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = {}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "customer_orders = set()\n", + "\n", + "product1 = input(\"Ingresa el nombre del primer producto que deseas: \").lower()\n", + "product2 = input(\"Ingresa el nombre del segundo producto que deseas: \").lower()\n", + "product3 = input(\"Ingresa el nombre del tercer producto que deseas: \").lower()\n", + "\n", + "customer_orders.add(product1)\n", + "customer_orders.add(product2)\n", + "customer_orders.add(product3)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Print the products in the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'pencil', 'paper', 'pen'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "7. Calculate the following order statistics:\n", + " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + " \n", + " Store these statistics in a tuple called `order_status`." + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len (customer_orders)\n", + "percentage_ordered = (total_products_ordered/len(products))*100\n", + "order_status =(total_products_ordered/percentage_ordered)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.0%\n" + ] + } + ], + "source": [ + "print(\"Order statistics:\")\n", + "print(f\"Total products ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of products ordered: {percentage_ordered:}%\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "inventory={}\n", + "\n", + "inventory[\"t-shirt\"] = valor_tshirt - 1\n", + "inventory[\"mug\"] = valor_mug - 1\n", + "inventory[\"hat\"] = valor_hat - 1\n", + "inventory[\"book\"] = valor_book - 1\n", + "inventory[\"keychain\"] = valor_keychain - 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventory:\n", + "t-shirt: 4\n", + "mug: 9\n", + "hat: 6\n", + "book: 3\n", + "keychain: 1\n" + ] + } + ], + "source": [ + "print(\"Updated Inventory:\")\n", + "print(f\"t-shirt: {inventory['t-shirt']}\")\n", + "print(f\"mug: {inventory['mug']}\")\n", + "print(f\"hat: {inventory['hat']}\")\n", + "print(f\"book: {inventory['book']}\")\n", + "print(f\"keychain: {inventory['keychain']}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +327,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 2a2048f50c2ff5719d5f5e4f53dc4a457caba350 Mon Sep 17 00:00:00 2001 From: Javier Soto Date: Mon, 6 Oct 2025 18:50:46 +0200 Subject: [PATCH 2/2] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index fcf8265d..d0bcf7b9 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -211,13 +211,13 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "total_products_ordered = len (customer_orders)\n", "percentage_ordered = (total_products_ordered/len(products))*100\n", - "order_status =(total_products_ordered/percentage_ordered)\n", + "order_status =(total_products_ordered,percentage_ordered)\n", "\n" ] },