From 04660078eb3af7c71b8a3dd42b3326ea547a35cb Mon Sep 17 00:00:00 2001 From: your_username Date: Tue, 15 Oct 2024 09:16:24 +0200 Subject: [PATCH] Up2date --- lab-python-data-structures.ipynb | 307 ++++++++++++++++++++++++++++++- 1 file changed, 306 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e..1f4d591 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,311 @@ "\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": [ + "#1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "#2\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Ingresa la cantidad de t-shirt: 4\n", + "Ingresa la cantidad de mug: 5\n", + "Ingresa la cantidad de hat: 2\n", + "Ingresa la cantidad de book: 3\n", + "Ingresa la cantidad de keychain: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventario actual:\n", + "{'t-shirt': 4, 'mug': 5, 'hat': 2, 'book': 3, 'keychain': 5}\n" + ] + } + ], + "source": [ + "#3\n", + "# Recorrer la lista de productos y solicitar la cantidad para cada uno\n", + "\n", + "for product in products:\n", + " # Pedir al usuario ingresar la cantidad para cada producto\n", + " quantity = int(input(f\"Ingresa la cantidad de {product}: \"))\n", + " # Asignar la cantidad en el diccionario \"inventory\"\n", + " inventory[product] = quantity\n", + "\n", + "# Mostrar el inventario resultante\n", + "print(\"Inventario actual:\")\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "#4\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Ingresa nombre de product1: mug\n", + "Ingresa nombre de product2: book\n", + "Ingresa nombre de product3: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Nombre de productos que contiene la órden:\n", + "{'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "#5\n", + "# Pedir al usuario ingresar los 3 tipos de producto que quiere en su orden\n", + "product1_name = input(f\"Ingresa nombre de product1: \")\n", + "product2_name = input(f\"Ingresa nombre de product2: \")\n", + "product3_name = input(f\"Ingresa nombre de product3: \")\n", + "# Asignar el nombre de producto en el set \"customer_orders\"\n", + "customer_orders.add (product1_name)\n", + "customer_orders.add (product2_name)\n", + "customer_orders.add (product3_name)\n", + "\n", + "print(\"Nombre de productos que contiene la órden:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Órden de cliente:\n", + "{'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "#6\n", + "# Mostrar la customer order resultante\n", + "print(\"Órden de cliente:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "#7\n", + "#Total Products Number\n", + "total_products_number = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_products_number" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "#Percentage of Products Ordered\n", + "percentage_products_ordered = int((total_products_number / len(products))*100)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "60" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "percentage_products_ordered" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [], + "source": [ + "#Guardar las estadísticas en una tupla\n", + "statistics = (total_products_number,percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60)" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60\n" + ] + } + ], + "source": [ + "#8\n", + "#Mostrar las estadísticas\n", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_number)\n", + "print(\"Percentage of Products Ordered:\", percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "#9\n", + "for i in inventory:\n", + " inventory[i]-=1" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 3, 'mug': 4, 'hat': 1, 'book': 2, 'keychain': 4}" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt 3\n", + "mug 4\n", + "hat 1\n", + "book 2\n", + "keychain 4\n" + ] + } + ], + "source": [ + "#10\n", + "#Mostrar el inventario actualizado\n", + "for x,i in inventory.items():\n", + " print (x,i)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +373,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.4" } }, "nbformat": 4,