diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..8962e628 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,188 @@ "\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": [ + "# PUNTO 1\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "# PUNTO 2\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 2, 'mug': 2, 'hat': 2, 'book': 2, 'keychain': 2}\n" + ] + } + ], + "source": [ + "# PUNTO 3\n", + "numero_camisetas = int(input(\"Introduzca el número de camisetas:\"))\n", + "inventory [\"t-shirt\"] = numero_camisetas\n", + "numero_tazas = int(input(\"Introduzca el número de tazas:\"))\n", + "inventory [\"mug\"] = numero_tazas\n", + "numero_sombreros = int(input(\"Introduzca el número de sombreros:\"))\n", + "inventory [\"hat\"] = numero_sombreros\n", + "numero_libros = int(input(\"Introduzca el número de libros:\"))\n", + "inventory [\"book\"] = numero_libros\n", + "numero_llaveros = int(input(\"Introduzca el número de llaveros:\"))\n", + "inventory [\"keychain\"] = numero_llaveros\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "#PUNTO 4\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Artículos elegidos: {'mug', 'hat', 'keychain'}\n" + ] + } + ], + "source": [ + "#PUNTO 5\n", + "item1 = input(\"Por favor, escoja tres: t-shirt, mug, hat, book o keychain: \")\n", + "item2 = input(\"Segunda elección: \")\n", + "item3 = input(\"Tercera elección: \")\n", + "customer_orders.add(item1)\n", + "customer_orders.add(item2)\n", + "customer_orders.add(item3)\n", + "print(\"Artículos elegidos:\", customer_orders)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "#PUNTO 6\n", + "total_products_ordered=len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n", + "(3, 60.0)\n" + ] + } + ], + "source": [ + "#PUNTO 7\n", + "customer_percentage = len(customer_orders)/len(products) * 100\n", + "print (customer_percentage)\n", + "order_status= (len(customer_orders), customer_percentage )\n", + "print (order_status)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "#PUNTO 8\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {customer_percentage}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 1, 'mug': 1, 'hat': 1, 'book': 1, 'keychain': 1}\n" + ] + } + ], + "source": [ + "#punto 9\n", + "inventory [\"t-shirt\"] += -1\n", + "inventory [\"mug\"] += -1\n", + "inventory [\"hat\"] += -1\n", + "inventory [\"book\"] += -1\n", + "inventory [\"keychain\"] += -1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 1\n", + "mug: 1\n", + "hat: 1\n", + "book: 1\n", + "keychain: 1\n" + ] + } + ], + "source": [ + "#PUNTO 10\n", + "print(f\"t-shirt: {inventory[\"t-shirt\"]}\")\n", + "print(f\"mug: {inventory[\"mug\"]}\")\n", + "print(f\"hat: {inventory[\"hat\"]}\")\n", + "print(f\"book: {inventory[\"book\"]}\")\n", + "print(f\"keychain: {inventory[\"keychain\"]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +245,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,