diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb new file mode 100644 index 00000000..bb29dcf8 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,477 @@ +{ + "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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 123\n", + "Enter the quantity for mug: 358\n", + "Enter the quantity for hat: 904\n", + "Enter the quantity for book: 529\n", + "Enter the quantity for keychain: 508\n" + ] + } + ], + "source": [ + "# first trial\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508, 2: 508}\n" + ] + } + ], + "source": [ + "# dicionario[chave] = valor\n", + "inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 123\n", + "Enter the quantity for mug: 358\n", + "Enter the quantity for hat: 904\n", + "Enter the quantity for book: 529\n", + "Enter the quantity for keychain: 508\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508}\n" + ] + } + ], + "source": [ + "# let's try again\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of 3 products from the list: mug t-shirt hat\n", + "Enter the name of 3 products from the list: pen mug hat\n", + "Enter the name of 3 products from the list: keychain t-shirt book pen\n", + "Enter the name of 3 products from the list: eodfjsodf\n", + "Enter the name of 3 products from the list: sdf ;_;\n" + ] + } + ], + "source": [ + "customer_orders = {}\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in products: #im not specifying that i want only 3 products\n", + " if product in products: \n", + " str(input(\"Enter the name of 3 products from the list: \"))\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: pen\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + } + ], + "source": [ + "# customer_orders = ???\n", + "\n", + "#for ???:\n", + " #order = input(...)\n", + "\n", + " #if ...:\n", + " \n", + " #else:\n", + "\n", + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3): #now yes\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if product in products: #problemmmmm\n", + " print(f\"Order: {product}\")\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 0\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: keychain\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 1\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: t-shirt\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 2\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3):\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if order in products: \n", + " print(f\"Order: {product}\") # problemm\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt'}\n" + ] + } + ], + "source": [ + "customer_orders.add(order)\n", + "print(customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: mug\n", + "Place your order: keychain\n", + "Place your order: hat\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3):\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if order in products: \n", + " customer_orders.add(order) #.add when we're talking about set's\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'keychain'}\n" + ] + } + ], + "source": [ + "customer_orders.add(order)\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n" + ] + } + ], + "source": [ + "percentage_products_ordered = len(customer_orders) / len(products) * 100\n", + "print(percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 60.0)\n" + ] + } + ], + "source": [ + "order_status = (total_products_ordered, percentage_products_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: Total Products Ordered: 3, Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "print(f\"Order Statistics: Total Products Ordered: {total_products_ordered}, Percentage of Products Ordered: {percentage_products_ordered}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The quantity of t-shirt is 122\n", + "The quantity of mug is 357\n", + "The quantity of hat is 903\n", + "The quantity of book is 528\n", + "The quantity of keychain is 507\n" + ] + } + ], + "source": [ + "# Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly.\n", + "\n", + "inventory = {'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508}\n", + "\n", + "for product in products:\n", + " inventory[product] = inventory[product] - 1\n", + " print(f\"The quantity of {product} is {inventory[product]}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:anaconda3]", + "language": "python", + "name": "conda-env-anaconda3-py" + }, + "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.13.9" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..bb29dcf8 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,414 @@ "\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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 123\n", + "Enter the quantity for mug: 358\n", + "Enter the quantity for hat: 904\n", + "Enter the quantity for book: 529\n", + "Enter the quantity for keychain: 508\n" + ] + } + ], + "source": [ + "# first trial\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508, 2: 508}\n" + ] + } + ], + "source": [ + "# dicionario[chave] = valor\n", + "inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the quantity for t-shirt: 123\n", + "Enter the quantity for mug: 358\n", + "Enter the quantity for hat: 904\n", + "Enter the quantity for book: 529\n", + "Enter the quantity for keychain: 508\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508}\n" + ] + } + ], + "source": [ + "# let's try again\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the name of 3 products from the list: mug t-shirt hat\n", + "Enter the name of 3 products from the list: pen mug hat\n", + "Enter the name of 3 products from the list: keychain t-shirt book pen\n", + "Enter the name of 3 products from the list: eodfjsodf\n", + "Enter the name of 3 products from the list: sdf ;_;\n" + ] + } + ], + "source": [ + "customer_orders = {}\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in products: #im not specifying that i want only 3 products\n", + " if product in products: \n", + " str(input(\"Enter the name of 3 products from the list: \"))\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: pen\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Product is not in the list\n" + ] + } + ], + "source": [ + "# customer_orders = ???\n", + "\n", + "#for ???:\n", + " #order = input(...)\n", + "\n", + " #if ...:\n", + " \n", + " #else:\n", + "\n", + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3): #now yes\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if product in products: #problemmmmm\n", + " print(f\"Order: {product}\")\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 0\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: keychain\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 1\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: t-shirt\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order: 2\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3):\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if order in products: \n", + " print(f\"Order: {product}\") # problemm\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt'}\n" + ] + } + ], + "source": [ + "customer_orders.add(order)\n", + "print(customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Place your order: mug\n", + "Place your order: keychain\n", + "Place your order: hat\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "for product in range(3):\n", + " order = str(input(\"Place your order: \"))\n", + "\n", + " if order in products: \n", + " customer_orders.add(order) #.add when we're talking about set's\n", + " else:\n", + " print(\"Product is not in the list\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'keychain'}\n" + ] + } + ], + "source": [ + "customer_orders.add(order)\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n" + ] + } + ], + "source": [ + "percentage_products_ordered = len(customer_orders) / len(products) * 100\n", + "print(percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 60.0)\n" + ] + } + ], + "source": [ + "order_status = (total_products_ordered, percentage_products_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: Total Products Ordered: 3, Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "print(f\"Order Statistics: Total Products Ordered: {total_products_ordered}, Percentage of Products Ordered: {percentage_products_ordered}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The quantity of t-shirt is 122\n", + "The quantity of mug is 357\n", + "The quantity of hat is 903\n", + "The quantity of book is 528\n", + "The quantity of keychain is 507\n" + ] + } + ], + "source": [ + "# Update the inventory by subtracting 1 from the quantity of each product. Modify the inventory dictionary accordingly.\n", + "\n", + "inventory = {'t-shirt': 123, 'mug': 358, 'hat': 904, 'book': 529, 'keychain': 508}\n", + "\n", + "for product in products:\n", + " inventory[product] = inventory[product] - 1\n", + " print(f\"The quantity of {product} is {inventory[product]}\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:anaconda3]", "language": "python", - "name": "python3" + "name": "conda-env-anaconda3-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +469,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,