From 870b38d72fb1c59034d9325d183344ebaabeea18 Mon Sep 17 00:00:00 2001 From: loreS23-dot Date: Tue, 4 Nov 2025 17:45:21 +0100 Subject: [PATCH] strutures lab --- lab-python-data-structures.ipynb | 146 ++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..53eda78d 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,153 @@ "\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": 1, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "for product in products:\n", + " quantity = int(input(f\"Introduce la cantidad de los productos {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "customers_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elige tres productos para pedir (t-shirt, mug, hat, book, keychain):\n" + ] + } + ], + "source": [ + "print(\"Elige tres productos para pedir (t-shirt, mug, hat, book, keychain):\")\n", + "for x in range(3):\n", + " order = input(f\"Producto {x+1}: \")\n", + " customers_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Productos pedidos: {'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "print(\"Productos pedidos:\", customers_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customers_orders) \n", + "percentage_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0 %\n" + ] + } + ], + "source": [ + "print(\"\\nOrder Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customers_orders:\n", + " inventory[item] = inventory[item] - 1" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventario actualizado:\n", + "t-shirt : 20\n", + "mug : 19\n", + "hat : 19\n", + "book : 19\n", + "keychain : 20\n" + ] + } + ], + "source": [ + "print(\"Inventario actualizado:\")\n", + "for product in inventory:\n", + " print(product, \":\", inventory[product])" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +210,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.9" } }, "nbformat": 4,