diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..60e3f581 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,181 @@ "\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": [ + "#paso 1-Creo la lista de productos\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#paso 2-Creo el diccionario vacío\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Introduce la cantidad disponible de cada producto:\n" + ] + } + ], + "source": [ + "#paso 3-Pido al usuario la cantidad de cada producto\n", + "print(\"Introduce la cantidad disponible de cada producto:\")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 12, 'mug': 23, 'hat': 21, 'book': 44, 'keychain': 64}\n" + ] + } + ], + "source": [ + "#compruebo el inventario\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#paso 5- Pedir 3 productos al cliente\n", + "print(\"Introduce 3 productos que el cliente quiere comprar:\")\n", + "\n", + "while len(customer_orders) < 3:\n", + " product = input(\"Producto: \").lower()\n", + "\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Producto inválido. Usa uno de estos:\", products)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Productos pedidos:\n" + ] + }, + { + "ename": "NameError", + "evalue": "name 'customer_orders' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[8]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m#paso 6-Mostrar los productos pedidos\u001b[39;00m\n\u001b[32m 2\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mProductos pedidos:\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[43mcustomer_orders\u001b[49m)\n", + "\u001b[31mNameError\u001b[39m: name 'customer_orders' is not defined" + ] + } + ], + "source": [ + "#paso 6-Mostrar los productos pedidos\n", + "print(\"Productos pedidos:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'customer_orders' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m#paso 7- Calcular estadísticas del pedido\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m total_products_ordered = \u001b[38;5;28mlen\u001b[39m(\u001b[43mcustomer_orders\u001b[49m)\n\u001b[32m 3\u001b[39m percentage_ordered = (total_products_ordered / \u001b[38;5;28mlen\u001b[39m(products)) * \u001b[32m100\u001b[39m\n\u001b[32m 5\u001b[39m order_status = (total_products_ordered, percentage_ordered)\n", + "\u001b[31mNameError\u001b[39m: name 'customer_orders' is not defined" + ] + } + ], + "source": [ + "#paso 7- Calcular estadísticas del pedido\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + "order_status = (total_products_ordered, percentage_ordered)\n", + "print(\"Estado del pedido (total productos, porcentaje del inventario):\", order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#paso 8- mostrar las estadisticas del pedido\n", + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#paso 9- actualizamos el inventario\n", + "for product in customer_orders:\n", + " inventory[product] -= 1\n", + "print(\"Inventario actualizado:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#paso 10- mostramos el inventario actualizado\n", + "print(\"Inventario actualizado:\")\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(product, \":\", quantity)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +238,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.0" } }, "nbformat": 4,