diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..02a9b8b3 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,167 @@ "\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": 5, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 1: Define the list of products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 2: Create an inventory with predefined quantities\n", + "inventory = {\n", + " \"t-shirt\": 5,\n", + " \"mug\": 3,\n", + " \"hat\": 2,\n", + " \"book\": 4,\n", + " \"keychain\": 6\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 3: Create an empty set for customer orders\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 4: Simulate user selecting three products\n", + "selected_orders = [\"mug\", \"book\", \"hat\"] # puedes cambiar estos valores\n", + "for order in selected_orders:\n", + " if order in products:\n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Customer Orders:\n", + "- hat\n", + "- mug\n", + "- book\n" + ] + } + ], + "source": [ + "# Step 5: Print customer orders\n", + "print(\"\\nCustomer Orders:\")\n", + "for item in customer_orders:\n", + " print(\"-\", item)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Step 6: Calculate order statistics\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 7: Store statistics in a tuple\n", + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "# Step 8: Print order statistics\n", + "print(\"\\nOrder Statistics:\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "# Step 9: Update inventory (subtract 1 for each ordered product)\n", + "for item in customer_orders:\n", + " if inventory[item] > 0:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory:\n", + "t-shirt: 5\n", + "mug: 2\n", + "hat: 1\n", + "book: 3\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "# Step 10: Print updated inventory\n", + "print(\"\\nUpdated Inventory:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +224,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.9" } }, "nbformat": 4,