diff --git a/Laboratorio1.ipynb b/Laboratorio1.ipynb new file mode 100644 index 00000000..23dc7f66 --- /dev/null +++ b/Laboratorio1.ipynb @@ -0,0 +1,274 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise: Managing Customer Orders\n", + "\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", + "\n", + "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", + "\n", + "8. Print the order statistics using the following format:\n", + " ```\n", + " Order Statistics:\n", + " Total Products Ordered: \n", + " Percentage of Products Ordered: % \n", + " ```\n", + "\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly.\n", + "\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": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "print (products)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventario = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Introduce la cantidad disponible para cada producto:\n" + ] + } + ], + "source": [ + "print(\"Introduce la cantidad disponible para cada producto:\")\n", + "\n", + "t_shirt = int(input(\"t-shirt: \"))\n", + "mug= int(input(\"mug: \"))\n", + "hat = int(input(\"hat: \"))\n", + "book = int(input(\"book: \"))\n", + "keychain = int(input(\"keychain: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t_shirt': 5, 'mug': 5, 'hat': 5, 'book': 5, 'keychain': 5}\n" + ] + } + ], + "source": [ + "inventario[\"t_shirt\"] = t_shirt\n", + "inventario[\"mug\"] = mug\n", + "inventario[\"hat\"] = hat\n", + "inventario[\"book\"] = book\n", + "inventario[\"keychain\"] = keychain\n", + "print (inventario)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elige tres productos de esta lista: t_shirt, mug, hat, book, keychain\n" + ] + } + ], + "source": [ + "print(\"Elige tres productos de esta lista: t_shirt, mug, hat, book, keychain\")\n", + "\n", + "products_1 = input(\"Primer producto: \")\n", + "products_2 = input(\"Segundo producto: \")\n", + "products_3 = input(\"Tercer producto: \")" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = {products_1, products_2, products_3}" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Productos en el pedido del cliente: \n", + "{'hat', 'book', 'keychain'}\n" + ] + } + ], + "source": [ + "print(\"Productos en el pedido del cliente: \")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_orderer = len(customer_orders)\n", + "percentage_ordered = (total_products_orderer * 100) / len(products)\n", + "order_status = (total_products_orderer, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "orden_status\n", + "Total Products Orderer: 3\n", + "Percentage of Products Orderer: 60.0 %\n" + ] + } + ], + "source": [ + "print(\"Orden_status\")\n", + "print(\"Total Products Orderer:\", order_status[0])\n", + "print(\"Percentage of Products Orderer:\", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "inventario[products_1] -= 1\n", + "inventario[products_2] -= 1\n", + "inventario[products_3] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t_shirt': 5, 'mug': 5, 'hat': 4, 'book': 4, 'keychain': 4}\n" + ] + } + ], + "source": [ + "print(inventario)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}