diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..c886fc99 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,67 @@ "\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": null, + "metadata": {}, + "outputs": [], + "source": [ + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "inventory = { }\n", + "# 1. Crear el inventario en una sola lĂ­nea (Dictionary Comprehension)\n", + "# Esto pide la cantidad para cada producto de la lista\n", + "inventory = {p: int(input(f\"Quantity of {p}: \")) for p in products}\n", + "\n", + "# 2. Crear el conjunto de pedidos\n", + "customer_orders = set()\n", + "\n", + "# 3. Pedir tres productos de forma sencilla\n", + "print(\"\\nEnter 3 products for your order from the following options:\" if products else \"No products available.\")\n", + "if products:\n", + " print(\", \".join(products))\n", + "customer_orders.add(input(\"Product 1: \"))\n", + "customer_orders.add(input(\"Product 2: \"))\n", + "customer_orders.add(input(\"Product 3: \"))\n", + " \n", + "print(customer_orders)\n", + "\n", + "\n", + "# Calculate the total products ordered\n", + "total_products_ordered = len(customer_orders)\n", + "\n", + "# Calculate the percentage of products ordered\n", + "total_available = len(products)\n", + "percentage_of_products_ordered = (total_products_ordered / total_available) * 100\n", + "\n", + "# Store the calculations in a tuple\n", + "order_status = (total_products_ordered, percentage_of_products_ordered)\n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n", + "\n", + "for item in customer_orders:\n", + " inventory[item] -= 1\n", + "\n", + "# 2. Imprimir el inventario actualizado\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +124,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.4" } }, "nbformat": 4,