diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..ddc51807 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,55 +1,305 @@ { "cells": [ { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, + "cell_type": "code", + "execution_count": 15, + "id": "d2e298e2-e589-4459-a82f-fd16e576d8eb", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a quantity 5\n", + "Enter a quantity 4\n", + "Enter a quantity 6\n", + "Enter a quantity 3\n", + "Enter a quantity 4\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "for product in products:\n", + " inventory[product]= int(input(\"Enter a quantity\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "72037821-51aa-4107-b906-8d3b5eb11f4b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 4, 'hat': 6, 'book': 3, 'keychain': 4}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "80e2572f-bcba-4e3b-8ce6-496da49fbc2f", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter a name t-shirt\n", + "Enter a name mug\n", + "Enter a name hat\n" + ] + } + ], + "source": [ + "customer_orders = set()\n", + "product1 = input('Enter a name')\n", + "product2 = input('Enter a name')\n", + "product3 = input('Enter a name')\n", + "customer_orders.add(product1)\n", + "customer_orders.add(product2)\n", + "customer_orders.add(product3)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "49f4e11a-232d-4f0a-9c39-ef73e2515442", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'hat', 'mug', 't-shirt'}" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "74d9c4c4-4ff5-4ecb-a81d-6f7923360372", + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "4221bd5c-5536-4d41-826e-49a9872ec2cd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "total_products_ordered " + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "429e8de7-ff78-410f-bc06-da6c13fe1542", + "metadata": {}, + "outputs": [], + "source": [ + "total_available = len(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "6b161f63-58c3-48ba-89b1-62721bfdecb7", + "metadata": {}, + "outputs": [], + "source": [ + "percentage_of_products = total_products_ordered/total_available" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "b6e6ea1b-cf6a-4edc-b6eb-64c8b0646a4a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.6" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "percentage_of_products" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "2a851ed0-f452-4131-a258-e90bac69076b", + "metadata": {}, + "outputs": [], + "source": [ + "order_status = ( total_products_ordered , percentage_of_products)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "1b5d3cc5-e38c-4b59-b379-d50821868762", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 0.6)" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "e7cdf6af-b61d-49a9-b8b0-612e8a557ff8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "tuple" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "a0eb953d-6dee-4d88-8767-c5b66b0723e7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:,\n", + "Total Products Ordered: 3,\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "print(f\"\\nOrder Statistics:,\\nTotal Products Ordered: {total_products_ordered},\\nPercentage of Products Ordered: {percentage_of_products*100}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "4c2a1508-ce14-4e83-9bb1-2891f6abc646", + "metadata": {}, + "outputs": [], + "source": [ + "for product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "7e58bf28-a82d-4b1f-99ce-335171161c6a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 4, 'mug': 3, 'hat': 5, 'book': 2, 'keychain': 3}" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "8c21cfcc-a1ed-448e-832b-2ef2a7f8bfbd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt 4\n", + "mug 3\n", + "hat 5\n", + "book 2\n", + "keychain 3\n" + ] + } + ], "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. " + "for key,values in inventory.items():\n", + " print(key,values)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "371d19bb-e2db-457b-b453-d9f0ee5fcc3f", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,9 +318,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.4" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 }