From 4e6230b890fc61ca3ba69810c31e619b5e033427 Mon Sep 17 00:00:00 2001 From: PabloFerreiraP Date: Tue, 15 Sep 2026 14:42:42 +0200 Subject: [PATCH 1/2] this is my solved lab --- lab-python-data-structures.ipynb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..3e23b9e6 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,19 @@ "\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": null, + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "solution" + ] } ], "metadata": { From 516916914f447abc283fa5fd81715afb5d623ca2 Mon Sep 17 00:00:00 2001 From: PabloFerreiraP Date: Tue, 15 Sep 2026 16:36:33 +0200 Subject: [PATCH 2/2] Update Python data structures lab --- lab-python-data-structures.ipynb | 351 ++++++++++++++++++++++++++++++- 1 file changed, 344 insertions(+), 7 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 3e23b9e6..471991c0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,15 +53,352 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "vscode": { - "languageId": "plaintext" + "execution_count": 98, + "metadata": {}, + "outputs": [], + "source": [ + "#1. Define a list called products that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"." + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [], + "source": [ + "#2. Create an empty dictionary called inventory." + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [], + "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": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter t-shirt quantity: 7\n", + "Enter mug quantity: 3\n", + "Enter hat quantity: 3\n", + "Enter book quantity: 4\n", + "Enter keychain quantity: 8\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 7, 'mug': 3, 'hat': 3, 'book': 4, 'keychain': 8}\n" + ] } - }, + ], + "source": [ + "item = products[0]\n", + "quantity = int(input(f\"Enter {item} quantity: \"))\n", + "inventory[item] = quantity\n", + "\n", + "item = products[1]\n", + "quantity = int(input(f\"Enter {item} quantity: \"))\n", + "inventory[item] = quantity\n", + "\n", + "item = products[2]\n", + "quantity = int(input(f\"Enter {item} quantity: \"))\n", + "inventory[item] = quantity\n", + "\n", + "item = products[3]\n", + "quantity = int(input(f\"Enter {item} quantity: \"))\n", + "inventory[item] = quantity\n", + "\n", + "item = products[4]\n", + "quantity = int(input(f\"Enter {item} quantity: \"))\n", + "inventory[item] = quantity\n", + "\n", + "print(\"Inventory: \" + str(inventory))" + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "#4. Create an empty set calledcustomer_orders." + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, "outputs": [], "source": [ - "solution" + "#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": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain? mug\n", + "What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain? hat\n", + "What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain? keychain\n" + ] + } + ], + "source": [ + "item1 = input (\"What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain?\")\n", + "customer_orders.add(item1)\n", + "\n", + "item2 = input (\"What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain?\")\n", + "customer_orders.add(item2)\n", + "\n", + "item3 = input (\"What would you like to order out of a t-shirt, a mug, a hat, a book or a keychain?\")\n", + "customer_orders.add(item3)" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [], + "source": [ + "#6. Print the products in the customer_orders set." + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer order: {'hat', 'keychain', 'mug'}\n" + ] + } + ], + "source": [ + "print(\"Customer order: \" + str(customer_orders))" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [], + "source": [ + "#7. Calculate the following order statistics: Total Products Ordered: The total number of products in the customer_orders set. Percentage of Products Ordered: The percentage of products ordered compared to the total available products. Store these statistics in a tuple called order_status." + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "12.0\n", + "5\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "percentage_products_ordered = (total_products_ordered / sum(inventory.values())) * 100\n", + "\n", + "print(total_products_ordered)\n", + "print(percentage_products_ordered)\n", + "print(len(products))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.0" + ] + }, + "execution_count": 117, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "percentage_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (\n", + " total_products_ordered,\n", + " percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 12.0)" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [], + "source": [ + "#8. Print the order statistics using the following format:" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 12.0\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [], + "source": [ + "#9. Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 7, 'mug': 2, 'hat': 2, 'book': 4, 'keychain': 7}\n" + ] + } + ], + "source": [ + "inventory[item1] -= 1\n", + "inventory[item2] -= 1\n", + "inventory[item3] -= 1\n", + "\n", + "print(\"Inventory:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [], + "source": [ + "#10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T-shirt: 7\n", + "Mug: 2\n", + "Hat: 2\n", + "Book: 4\n", + "Keychain: 7\n" + ] + } + ], + "source": [ + "print(\"T-shirt:\", inventory[\"t-shirt\"])\n", + "print(\"Mug:\", inventory[\"mug\"])\n", + "print(\"Hat:\", inventory[\"hat\"])\n", + "print(\"Book:\", inventory[\"book\"])\n", + "print(\"Keychain:\", inventory[\"keychain\"])" ] } ], @@ -81,7 +418,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,