From 4f2f6fe8681d358515a595d8864f357614a1ad1e Mon Sep 17 00:00:00 2001 From: Pedro Manuel Gil Basilio Ferreira Date: Wed, 19 Nov 2025 20:22:37 +0000 Subject: [PATCH 1/2] new --- lab-python-data-structures.ipynb | 72 ++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..9045df2b 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,79 @@ "\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": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the ammount for each t-shirt 3\n", + "Enter the ammount for each mug 4\n", + "Enter the ammount for each hat 3\n", + "Enter the ammount for each book 4\n", + "Enter the ammount for each keychain 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What are the 3 products do you want to order?\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Insert the product 1 hat\n", + "Insert the product 2 book\n", + "Insert the product 3 mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Products ordered are {'book', 'hat', 'mug'}\n", + "The total orders are 11\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"] \n", + "inventory = {}\n", + "for key in products:\n", + " number = int(input(f\"Enter the ammount for each {key}\"))\n", + " inventory[key] = number\n", + "customers_orders = set()\n", + "print(\"What are the 3 products do you want to order?\")\n", + "for x in range(3):\n", + " order = input(f\"Insert the product {x + 1}\")\n", + " customers_orders.add(order)\n", + "print(\"Products ordered are\", customers_orders)\n", + "total_number = 0\n", + "for key in customers_orders:\n", + " total_number += inventory[key]\n", + "print(\"The total orders are\", total_number)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +134,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 7f070e0b45d9cb2ae66deb9b4386464a49a70fcb Mon Sep 17 00:00:00 2001 From: Pedro Manuel Gil Basilio Ferreira Date: Sun, 23 Nov 2025 14:46:13 +0000 Subject: [PATCH 2/2] Lab solved --- lab-python-data-structures.ipynb | 41 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 9045df2b..bdf4a965 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -53,18 +53,25 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdin", "output_type": "stream", "text": [ - "Enter the ammount for each t-shirt 3\n", - "Enter the ammount for each mug 4\n", - "Enter the ammount for each hat 3\n", - "Enter the ammount for each book 4\n", - "Enter the ammount for each keychain 3\n" + "Enter the ammount for each t-shirt 2\n", + "Enter the ammount for each mug 3\n", + "Enter the ammount for each hat 2\n", + "Enter the ammount for each book 3\n", + "Enter the ammount for each keychain 4\n" ] }, { @@ -78,8 +85,8 @@ "name": "stdin", "output_type": "stream", "text": [ - "Insert the product 1 hat\n", - "Insert the product 2 book\n", + "Insert the product 1 book\n", + "Insert the product 2 hat\n", "Insert the product 3 mug\n" ] }, @@ -87,8 +94,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "Products ordered are {'book', 'hat', 'mug'}\n", - "The total orders are 11\n" + "Products ordered are {'book', 'mug', 'hat'}\n", + "Total products ordered are: 8\n", + "Percentage of products ordered is: 37.5 %)\n", + "2\n", + "2\n", + "1\n" ] } ], @@ -107,7 +118,15 @@ "total_number = 0\n", "for key in customers_orders:\n", " total_number += inventory[key]\n", - "print(\"The total orders are\", total_number)" + "percentage = (len(customers_orders) / total_number) * 100\n", + "print(\"Total products ordered are:\", total_number)\n", + "print(\"Percentage of products ordered is:\", percentage, \"%)\")\n", + "\n", + "for key in customers_orders:\n", + " if key in inventory:\n", + " inventory[key] - 1\n", + " subtract = inventory[key]\n", + " print(subtract - 1)" ] }, {