diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..3a6bd764 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -6,7 +6,7 @@ "tags": [] }, "source": [ - "# Lab | Data Structures " + "# Lab | Data Structures " ] }, { @@ -17,44 +17,351 @@ "\n", "As part of a business venture, you are starting an online store that sells various products. To ensure smooth operations, you need to develop a program that manages customer orders and inventory.\n", "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "\n", - "2. Create an empty dictionary called `inventory`.\n", - "\n", - "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "4. Create an empty set called `customer_orders`.\n", - "\n", - "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n", - "\n", - "6. Print the products in the `customer_orders` set.\n", + "Follow the steps below to complete the exercise:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "products" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Create an empty dictionary called `inventory`." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory = {}\n", + "inventory" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 100, 'mug': 200, 'hat': 300, 'book': 400, 'keychain': 500}\n" + ] + } + ], + "source": [ + "for x in products:\n", + " cantidad = int(input(f\"Quantity of {x}\" ))\n", + " inventory[x] = cantidad\n", + "print(inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Create an empty set called `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "print(type(customer_orders))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "for x in range(3):\n", + " valor_escogido = input('Choose one product of \"\"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\"')\n", + " if valor_escogido in products:\n", + " customer_orders.add(valor_escogido)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Print the products in the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'hat', 'book'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "7. Calculate the following order statistics:\n", " - Total Products Ordered: The total number of products in the `customer_orders` set.\n", " - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", " \n", - " Store these statistics in a tuple called `order_status`.\n", + " Store these statistics in a tuple called `order_status`." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total_Products_Ordered) is: 900\n" + ] + } + ], + "source": [ + "Total_Products_Ordered = []\n", + "\n", + "for x in customer_orders:\n", + " Total_Products_Ordered.append(inventory[x])\n", + "Sum_Products_Ordered = sum(Total_Products_Ordered)\n", + "print((f\"Total_Products_Ordered) is: {sum(Total_Products_Ordered)}\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total_Products_Available) is: 1500\n" + ] + } + ], + "source": [ + "Total_Products_Available = []\n", + "\n", + "for x in products:\n", + " Total_Products_Available.append(inventory[x])\n", + "Sum_Products_Available = sum(Total_Products_Available)\n", + "print((f\"Total_Products_Available) is: {Sum_Products_Available}\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Porcentage of products Ordered compared Available" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There is 900 for 1500 there is a 60 %\n" + ] + } + ], + "source": [ + "porcentaje_pedido = round(100*Sum_Products_Ordered/Sum_Products_Available,2)\n", "\n", + "print(f\"There is {Sum_Products_Ordered} for {Sum_Products_Available} there is a {round(porcentaje_pedido)} %\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "8. Print the order statistics using the following format:\n", " ```\n", " Order Statistics:\n", " Total Products Ordered: \n", " Percentage of Products Ordered: % \n", - " ```\n", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 900\n", + "Percentage of Products Ordered: 60.0% \n" + ] + } + ], + "source": [ + "print(f\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {Sum_Products_Ordered}\")\n", + "print(f\"Percentage of Products Ordered: {porcentaje_pedido}% \")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 99, 'mug': 199, 'hat': 299, 'book': 399, 'keychain': 499}\n" + ] + } + ], + "source": [ + "for x in products:\n", + " inventory[x] -= 1\n", + "print(inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 99\n", + "mug: 199\n", + "hat: 299\n", + "book: 399\n", + "keychain: 499\n", + "Se_acabo\n" + ] + } + ], + "source": [ + "for x in inventory:\n", + " print(f\"{x}: {inventory[x]}\")\n", "\n", - "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "print(\"Se_acabo.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +375,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,