From 12aa669179fb8b98ead8bed9ebe0244a101a136c Mon Sep 17 00:00:00 2001 From: ruiparreira75 Date: Thu, 20 Nov 2025 09:59:29 +0000 Subject: [PATCH 1/4] lab resolved v1 --- lab-python-data-structures.ipynb | 337 ++++++++++++++++++++++++++++++- 1 file changed, 336 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..985f1d4f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,341 @@ "\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": [ + "#1 Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#2 Create an empty dictionary called `inventory`.\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "How many quantities of t-shirts? 3\n", + "How many quantities of mugs? 5\n", + "How many quantities of hats? 6\n", + "How many quantities of books? 3\n", + "How many quantities of keychains? 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}\n" + ] + } + ], + "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\n", + "#`inventory` dictionary and assign the respective quantities as values.\n", + "inventory = {\"t-shirt\": [], \"mug\": [], \"hat\": [], \"book\": [], \"keychain\": []}\n", + "inventory[\"t-shirt\"] = input(\"How many quantities of t-shirts? \")\n", + "inventory[\"mug\"] = input(\"How many quantities of mugs? \")\n", + "inventory[\"hat\"] = input(\"How many quantities of hats? \")\n", + "inventory[\"book\"] = input(\"How many quantities of books? \")\n", + "inventory[\"keychain\"] = input(\"How many quantities of keychains? \")\n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "#4. Create an empty set called `customer_orders`.\n", + "customer_orders = set()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 1. The choices are t-shirt, mug, hat, book, keychain. mug\n", + "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 2. The choices are t-shirt, mug, hat, book, keychain. hat\n", + "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 3. The choices are t-shirt, mug, hat, book, keychain. book\n" + ] + } + ], + "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 \n", + "# of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", + "for i in range(3):\n", + " order = input(f\"Enter three products from {inventory} {i+1}. The choices are t-shirt, mug, hat, book, keychain.\").strip().lower()\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(f\"{order} is not on inventory. Please choose from {products}.\")\n", + "# used {i+1} to start asking for product 1, and not product 0. " + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'book', 'keychain'}\n" + ] + } + ], + "source": [ + "# 6. Print the products in the `customer_orders` set.\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "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": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print (total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23\n" + ] + } + ], + "source": [ + "total_inventory = sum(int(value) for value in inventory.values())\n", + "print(total_inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "13.043478260869565\n" + ] + } + ], + "source": [ + "percentage_ordered = total_products_ordered / total_inventory * 100\n", + "print(percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % " + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: total_products_ordered: 3\n", + "Percentage of Products Ordered: 13 %\n" + ] + } + ], + "source": [ + "print(\"Total Products Ordered: total_products_ordered:\",total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\",int(percentage_ordered),\"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#converted the float to int, to give a full number in percentage" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'keychain'}" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book': 1, 'hat': 1, 'keychain': 1}\n" + ] + } + ], + "source": [ + "orders = {\"book\": 1, \"hat\": 1, \"keychain\": 1}\n", + "print(orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [], + "source": [ + "for product, quantity in orders.items():\n", + " if product in inventory:\n", + " inventory[product] = int(inventory[product]) - quantity\n", + " else:\n", + " print(f\"No enough {product} in stock.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '3', 'mug': '5', 'hat': 3, 'book': 0, 'keychain': 3}\n" + ] + } + ], + "source": [ + "# 10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#The quantities of the inventory don't match, because I run 3 times, and kept substracting stock. " + ] } ], "metadata": { @@ -68,7 +403,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 756a774231d04c97885b8a8216c2fdd023012b5b Mon Sep 17 00:00:00 2001 From: ruiparreira75 Date: Fri, 21 Nov 2025 17:14:47 +0000 Subject: [PATCH 2/4] lab solved v2 --- lab-python-data-structures.ipynb | 81 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 985f1d4f..d9fa0527 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -73,25 +73,25 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "How many quantities of t-shirts? 3\n", + "How many quantities of t-shirts? 4\n", "How many quantities of mugs? 5\n", "How many quantities of hats? 6\n", - "How many quantities of books? 3\n", - "How many quantities of keychains? 6\n" + "How many quantities of books? 7\n", + "How many quantities of keychains? 8\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}\n" + "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}\n" ] } ], @@ -109,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -119,16 +119,16 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 1. The choices are t-shirt, mug, hat, book, keychain. mug\n", - "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 2. The choices are t-shirt, mug, hat, book, keychain. hat\n", - "Enter three products from {'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'} 3. The choices are t-shirt, mug, hat, book, keychain. book\n" + "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 1. The choices are t-shirt, mug, hat, book, keychain. mug\n", + "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 2. The choices are t-shirt, mug, hat, book, keychain. book\n", + "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 3. The choices are t-shirt, mug, hat, book, keychain. hat\n" ] } ], @@ -146,14 +146,14 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'hat', 'book', 'keychain'}\n" + "{'book', 'hat', 'mug'}\n" ] } ], @@ -169,22 +169,22 @@ "outputs": [], "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", + "# - 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`." + "# Store these statistics in a tuple called `order_status`." ] }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}\n" + "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}\n" ] } ], @@ -194,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -212,14 +212,14 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "23\n" + "30\n" ] } ], @@ -230,18 +230,19 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "13.043478260869565\n" + "10.0\n" ] } ], "source": [ + "# 7b Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", "percentage_ordered = total_products_ordered / total_inventory * 100\n", "print(percentage_ordered)" ] @@ -254,14 +255,14 @@ "source": [ "# 8. Print the order statistics using the following format:\n", " ```\n", - " Order Statistics:\n", - " Total Products Ordered: \n", - " Percentage of Products Ordered: % " + "# Order Statistics:\n", + " # Total Products Ordered: \n", + " # Percentage of Products Ordered: % " ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -269,7 +270,7 @@ "output_type": "stream", "text": [ "Total Products Ordered: total_products_ordered: 3\n", - "Percentage of Products Ordered: 13 %\n" + "Percentage of Products Ordered: 10 %\n" ] } ], @@ -289,16 +290,16 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'t-shirt': '3', 'mug': '5', 'hat': '6', 'book': '3', 'keychain': '6'}" + "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}" ] }, - "execution_count": 69, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -310,16 +311,16 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'book', 'hat', 'keychain'}" + "{'book', 'hat', 'mug'}" ] }, - "execution_count": 70, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -330,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -348,7 +349,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -361,14 +362,14 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '3', 'mug': '5', 'hat': 3, 'book': 0, 'keychain': 3}\n" + "{'t-shirt': '4', 'mug': '5', 'hat': 5, 'book': 6, 'keychain': 7}\n" ] } ], @@ -382,9 +383,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "#The quantities of the inventory don't match, because I run 3 times, and kept substracting stock. " - ] + "source": [] } ], "metadata": { From 9adf3a085ea9dd7d2d1973d4cd98f1fd57d856c8 Mon Sep 17 00:00:00 2001 From: ruiparreira75 Date: Fri, 21 Nov 2025 18:01:44 +0000 Subject: [PATCH 3/4] lab solved v3 --- lab-python-data-structures.ipynb | 148 ++++++++++++++++++++++--------- 1 file changed, 104 insertions(+), 44 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index d9fa0527..7d96f297 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -63,7 +63,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -73,7 +73,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -91,25 +91,24 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}\n" + "{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}\n" ] } ], "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\n", "#`inventory` dictionary and assign the respective quantities as values.\n", - "inventory = {\"t-shirt\": [], \"mug\": [], \"hat\": [], \"book\": [], \"keychain\": []}\n", - "inventory[\"t-shirt\"] = input(\"How many quantities of t-shirts? \")\n", - "inventory[\"mug\"] = input(\"How many quantities of mugs? \")\n", - "inventory[\"hat\"] = input(\"How many quantities of hats? \")\n", - "inventory[\"book\"] = input(\"How many quantities of books? \")\n", - "inventory[\"keychain\"] = input(\"How many quantities of keychains? \")\n", + "inventory[\"t-shirt\"] = int(input(\"How many quantities of t-shirts? \"))\n", + "inventory[\"mug\"] = int(input(\"How many quantities of mugs? \"))\n", + "inventory[\"hat\"] = int(input(\"How many quantities of hats? \"))\n", + "inventory[\"book\"] = int(input(\"How many quantities of books? \"))\n", + "inventory[\"keychain\"] = int(input(\"How many quantities of keychains? \"))\n", "print(inventory)\n" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -119,16 +118,49 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 1. The choices are t-shirt, mug, hat, book, keychain. mug\n", - "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 2. The choices are t-shirt, mug, hat, book, keychain. book\n", - "Enter three products from {'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'} 3. The choices are t-shirt, mug, hat, book, keychain. hat\n" + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 1. The choices are t-shirt, mug, hat, book, keychain. book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 'book'.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 2. The choices are t-shirt, mug, hat, book, keychain. hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 'hat'.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 3. The choices are t-shirt, mug, hat, book, keychain. mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Added 'mug'.\n" ] } ], @@ -139,21 +171,21 @@ " order = input(f\"Enter three products from {inventory} {i+1}. The choices are t-shirt, mug, hat, book, keychain.\").strip().lower()\n", " if order in products:\n", " customer_orders.add(order)\n", + " print(f\"Added '{order}'.\")\n", " else:\n", - " print(f\"{order} is not on inventory. Please choose from {products}.\")\n", - "# used {i+1} to start asking for product 1, and not product 0. " + " print(f\"{order} is not on inventory. Please choose from {products}.\")\n" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'book', 'hat', 'mug'}\n" + "{'mug', 'book', 'hat'}\n" ] } ], @@ -177,14 +209,14 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}\n" + "{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}\n" ] } ], @@ -194,7 +226,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -212,7 +244,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -230,20 +262,20 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "10.0\n" + "60.0\n" ] } ], "source": [ "# 7b Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - "percentage_ordered = total_products_ordered / total_inventory * 100\n", + "percentage_ordered = total_products_ordered / len(products) * 100\n", "print(percentage_ordered)" ] }, @@ -262,7 +294,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -270,7 +302,7 @@ "output_type": "stream", "text": [ "Total Products Ordered: total_products_ordered: 3\n", - "Percentage of Products Ordered: 10 %\n" + "Percentage of Products Ordered: 60 %\n" ] } ], @@ -290,16 +322,16 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'t-shirt': '4', 'mug': '5', 'hat': '6', 'book': '7', 'keychain': '8'}" + "{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}" ] }, - "execution_count": 14, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -311,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -320,7 +352,7 @@ "{'book', 'hat', 'mug'}" ] }, - "execution_count": 15, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -331,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -349,35 +381,63 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}\n" + ] + } + ], "source": [ - "for product, quantity in orders.items():\n", - " if product in inventory:\n", - " inventory[product] = int(inventory[product]) - quantity\n", - " else:\n", - " print(f\"No enough {product} in stock.\")" + "print(inventory)" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '4', 'mug': '5', 'hat': 5, 'book': 6, 'keychain': 7}\n" + "{'t-shirt': 3, 'mug': 4, 'hat': 5, 'book': 6, 'keychain': 7}\n" ] } ], "source": [ - "# 10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "for product in inventory:\n", + " inventory[product] -= 1\n", "print(inventory)" ] }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 3\n", + "mug: 4\n", + "hat: 5\n", + "book: 6\n", + "keychain: 7\n" + ] + } + ], + "source": [ + "# 10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, { "cell_type": "code", "execution_count": null, From 8d144474b84a604bd99b47f657f2aa6afe2d11e5 Mon Sep 17 00:00:00 2001 From: ruiparreira75 Date: Fri, 21 Nov 2025 20:43:42 +0000 Subject: [PATCH 4/4] lab solved V4 --- lab-python-data-structures.ipynb | 41 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 7d96f297..e81fc633 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -125,42 +125,42 @@ "name": "stdin", "output_type": "stream", "text": [ - "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 1. The choices are t-shirt, mug, hat, book, keychain. book\n" + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 1. The choices are t-shirt, mug, hat, book, keychain. mug\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Added 'book'.\n" + "Added 'mug'.\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ - "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 2. The choices are t-shirt, mug, hat, book, keychain. hat\n" + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 2. The choices are t-shirt, mug, hat, book, keychain. book\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Added 'hat'.\n" + "Added 'book'.\n" ] }, { "name": "stdin", "output_type": "stream", "text": [ - "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 3. The choices are t-shirt, mug, hat, book, keychain. mug\n" + "Enter three products from {'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8} 3. The choices are t-shirt, mug, hat, book, keychain. hat\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Added 'mug'.\n" + "Added 'hat'.\n" ] } ], @@ -185,7 +185,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{'mug', 'book', 'hat'}\n" + "{'book', 'hat', 'mug'}\n" ] } ], @@ -279,6 +279,15 @@ "print(percentage_ordered)" ] }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -294,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -322,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -331,7 +340,7 @@ "{'t-shirt': 4, 'mug': 5, 'hat': 6, 'book': 7, 'keychain': 8}" ] }, - "execution_count": 12, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -343,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -352,7 +361,7 @@ "{'book', 'hat', 'mug'}" ] }, - "execution_count": 13, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -363,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -381,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -398,7 +407,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -417,7 +426,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [ {