From 3f961fc99821176dae1f776b7f27c98cd8c0688a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ruiz=20Bellido?= Date: Mon, 12 Jan 2026 15:14:15 +0100 Subject: [PATCH 1/3] resolved --- lab-python-data-structures.ipynb | 93 +++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..b5fcee18 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,100 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '5', 'mug': '5', 'hat': '5', 'book': '5', 'keychain': '5'}\n" + ] + } + ], + "source": [ + "# 3. Ask the user to input the quantity of each product available in the inventory. \n", + "# Use the product names from the `products` list as keys in the `inventory` dictionary \n", + "# and assign the respective quantities as values.\n", + "\n", + "quantity_t_shirt = input(\"Enter the quantity of t-shirt: \")\n", + "inventory['t-shirt'] = quantity_t_shirt\n", + "quantity_mug = input(\"Enter the quantity of mug: \")\n", + "inventory['mug'] = quantity_mug\n", + "quantity_hat = input(\"Enter the quantity of hat: \")\n", + "inventory['hat'] = quantity_hat\n", + "quantity_book = input(\"Enter the quantity of book: \")\n", + "inventory['book'] = quantity_book\n", + "quantity_keychain = input(\"Enter the quantity of keychain: \")\n", + "inventory['keychain'] = quantity_keychain\n", + "\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "# 4. Create an empty set called `customer_orders`.\n", + "\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt,', 'mug']\n", + "{'banana, coma', 't-shirt, banana', 'bana', 't-shirt, mug, hat'}\n" + ] + } + ], + "source": [ + "# 5. Ask the user to input the name of three products that a \n", + "# customer wants to order (from those in the products list, \n", + "# meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\"\n", + "# or \"keychain\". Add each product name to the `customer_orders` \n", + "# set.\n", + "\n", + "user_input1 = input(f'Enter one product from {products}: ')\n", + "user_input2 = input(f'Enter another product from {products}: ')\n", + "user_input3 = (f'Enter one last product from {products}: ')\n", + "\n", + "print(customer_orders)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +157,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4, From 72a6236464cef44f823a1a023b39495b55facb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ruiz=20Bellido?= Date: Mon, 12 Jan 2026 16:16:24 +0100 Subject: [PATCH 2/3] lab-python-data-structures: resolved --- lab-python-data-structures.ipynb | 135 ++++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index b5fcee18..98b55779 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -71,14 +71,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '5', 'mug': '5', 'hat': '5', 'book': '5', 'keychain': '5'}\n" + "{'t-shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n" ] } ], @@ -87,15 +87,15 @@ "# Use the product names from the `products` list as keys in the `inventory` dictionary \n", "# and assign the respective quantities as values.\n", "\n", - "quantity_t_shirt = input(\"Enter the quantity of t-shirt: \")\n", + "quantity_t_shirt = int(input(\"Enter the quantity of t-shirt: \"))\n", "inventory['t-shirt'] = quantity_t_shirt\n", - "quantity_mug = input(\"Enter the quantity of mug: \")\n", + "quantity_mug = int(input(\"Enter the quantity of mug: \"))\n", "inventory['mug'] = quantity_mug\n", - "quantity_hat = input(\"Enter the quantity of hat: \")\n", + "quantity_hat = int(input(\"Enter the quantity of hat: \"))\n", "inventory['hat'] = quantity_hat\n", - "quantity_book = input(\"Enter the quantity of book: \")\n", + "quantity_book = int(input(\"Enter the quantity of book: \"))\n", "inventory['book'] = quantity_book\n", - "quantity_keychain = input(\"Enter the quantity of keychain: \")\n", + "quantity_keychain = int(input(\"Enter the quantity of keychain: \"))\n", "inventory['keychain'] = quantity_keychain\n", "\n", "print(inventory)" @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -121,8 +121,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['t-shirt,', 'mug']\n", - "{'banana, coma', 't-shirt, banana', 'bana', 't-shirt, mug, hat'}\n" + "{'mug', 't-shirt', 'hat'}\n" ] } ], @@ -135,10 +134,124 @@ "\n", "user_input1 = input(f'Enter one product from {products}: ')\n", "user_input2 = input(f'Enter another product from {products}: ')\n", - "user_input3 = (f'Enter one last product from {products}: ')\n", + "user_input3 = input(f'Enter one last product from {products}: ')\n", + "customer_orders.add(user_input1)\n", + "customer_orders.add(user_input2)\n", + "customer_orders.add(user_input3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 6. Print the products in the `customer_orders` set.\n", "\n", "print(customer_orders)" ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "# 7. Calculate the following order statistics:\n", + "# - Total Products Ordered: The total number of products \n", + "# in the `customer_orders` set.\n", + "# - Percentage of Products Ordered: The percentage of products \n", + "# ordered compared to the total available products.\n", + "# Store these statistics in a tuple called `order_status`.\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_of_prodcuts_ordered = total_products_ordered/len(products)*100\n", + "order_status = (total_products_ordered, percentage_of_prodcuts_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: <3>.\n", + "Percentage of Products Ordered: <60.0>%\n" + ] + } + ], + "source": [ + "# 8. Print the order statistics using the following format:\n", + "# ```\n", + "# Order Statistics:\n", + "# Total Products Ordered: \n", + "# Percentage of Products Ordered: % \n", + "# ```\n", + "print(\n", + " f'Order Statistics:\\n'\n", + " f'Total Products Ordered: <{total_products_ordered}>.\\n'\n", + " f'Percentage of Products Ordered: <{percentage_of_prodcuts_ordered}>%'\n", + ")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 4, 'mug': 4, 'hat': 4, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "# 9. Update the inventory by subtracting 1 from the quantity \n", + "# of each product. Modify the `inventory` dictionary accordingly.\n", + "\n", + "inventory[\"t-shirt\"] -= 1\n", + "inventory[\"mug\"] -= 1\n", + "inventory[\"hat\"] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is the upadted inventory: \n", + "T-shirt: 4\n", + "Mug: 4\n", + "Hat: 4\n", + "Book: 5\n", + "Keychain: 5\n", + "\n" + ] + } + ], + "source": [ + "# 10. Print the updated inventory, displaying the quantity \n", + "# of each product on separate lines.\n", + "\n", + "print(\n", + " f'This is the upadted inventory: \\n'\n", + " f'T-shirt: {inventory[\"t-shirt\"]}\\n'\n", + " f'Mug: {inventory[\"mug\"]}\\n'\n", + " f'Hat: {inventory[\"hat\"]}\\n'\n", + " f'Book: {inventory[\"book\"]}\\n'\n", + " f'Keychain: {inventory[\"keychain\"]}\\n'\n", + ")" + ] } ], "metadata": { From f5a25b2274935e1187f6cfc6b250f41045a9fd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Ruiz=20Bellido?= Date: Mon, 12 Jan 2026 16:31:04 +0100 Subject: [PATCH 3/3] resolve completely --- lab-python-data-structures.ipynb | 54 ++++++++++++++------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 98b55779..b7b38a56 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -71,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -114,17 +114,9 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'mug', 't-shirt', 'hat'}\n" - ] - } - ], + "outputs": [], "source": [ "# 5. Ask the user to input the name of three products that a \n", "# customer wants to order (from those in the products list, \n", @@ -142,9 +134,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'hat', 'book'}\n" + ] + } + ], "source": [ "# 6. Print the products in the `customer_orders` set.\n", "\n", @@ -153,7 +153,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -200,29 +200,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 4, 'mug': 4, 'hat': 4, 'book': 5, 'keychain': 5}\n" - ] - } - ], + "outputs": [], "source": [ "# 9. Update the inventory by subtracting 1 from the quantity \n", "# of each product. Modify the `inventory` dictionary accordingly.\n", "\n", "inventory[\"t-shirt\"] -= 1\n", "inventory[\"mug\"] -= 1\n", - "inventory[\"hat\"] -= 1" + "inventory[\"hat\"] -= 1\n", + "inventory[\"book\"] -= 1\n", + "inventory[\"keychain\"] -= 1\n" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -233,8 +227,8 @@ "T-shirt: 4\n", "Mug: 4\n", "Hat: 4\n", - "Book: 5\n", - "Keychain: 5\n", + "Book: 4\n", + "Keychain: 4\n", "\n" ] }