diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..9dba5a5f Binary files /dev/null and b/.DS_Store differ diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb deleted file mode 100644 index 5b3ce9e0..00000000 --- a/lab-python-data-structures.ipynb +++ /dev/null @@ -1,76 +0,0 @@ -{ - "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. " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.9.13" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/lab_python_data_structures.ipynb b/lab_python_data_structures.ipynb new file mode 100644 index 00000000..12ceefad --- /dev/null +++ b/lab_python_data_structures.ipynb @@ -0,0 +1,397 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [], + "id": "n7x2_c9af9Bq" + }, + "source": [ + "# Lab | Data Structures" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-D2XjNJhf9Bt" + }, + "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", + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #creating product list\n", + "print(products)\n", + "type(products)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "UuAQEo9nf_ST", + "outputId": "da5c2695-3fd8-4be5-c79a-6d246a5a2707" + }, + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "list" + ] + }, + "metadata": {}, + "execution_count": 1 + } + ] + }, + { + "cell_type": "code", + "source": [ + "inventory={} #creating empty dictionary\n", + "print(inventory)\n", + "type(inventory)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "D5gsoE9HgNUg", + "outputId": "71ecd8c8-f48b-4117-f66a-3e362c295595" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{}\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "dict" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ] + }, + { + "cell_type": "code", + "source": [ + "products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #populating empty dictionary with key: product and values:quantity\n", + "inventory = {}\n", + "\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity {product}:\"))\n", + " inventory [product]=quantity\n", + "print(inventory)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "A8C5-z2BgRRW", + "outputId": "9b406d13-bdab-4c1a-d97c-21b45846b178" + }, + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter the quantity t-shirt:10\n", + "Enter the quantity mug:20\n", + "Enter the quantity hat:30\n", + "Enter the quantity book:40\n", + "Enter the quantity keychain:10\n", + "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 10}\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "customer_orders=set () #creating empty set\n", + "print(customer_orders)\n", + "type(customer_orders)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "sC4fxnNGgWE6", + "outputId": "bd98d11c-1bde-45d2-fcf4-e5ebb84b390a" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "set()\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "set" + ] + }, + "metadata": {}, + "execution_count": 4 + } + ] + }, + { + "cell_type": "code", + "source": [ + "customer_orders1={\"\",\"\"} #creating empty set\n", + "type(customer_orders1)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "oJgauQawgcUt", + "outputId": "07ca153c-0268-4821-a84a-bb5dc42ed516" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "set" + ] + }, + "metadata": {}, + "execution_count": 5 + } + ] + }, + { + "cell_type": "code", + "source": [ + "x,y,z = input(\"Enter three products:\").split() #taking products from user to be stored in customer_orders1 (set)\n", + "\n", + "print(x,y,z)\n", + "customer_orders1={x,y,z}\n", + "print(customer_orders1)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "4D2A8DTSggVI", + "outputId": "a5de7cde-5b80-4f30-d2cd-ef525b233a40" + }, + "execution_count": 6, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Enter three products:t-shirt mug book\n", + "t-shirt mug book\n", + "{'mug', 't-shirt', 'book'}\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "total_products=len(inventory) #calculating percentage of products ordered against the total number of products availabe\n", + "print(\"Total number of products in the inventory is:\", total_products)\n", + "total_products_ordered=len(customer_orders1)\n", + "print(\"Total number of products ordered is:\", total_products_ordered)\n", + "percentage_ordered=(total_products_ordered/total_products)*100\n", + "print(\"percentage ordered:\",percentage_ordered)\n", + "order_status=(total_products, percentage_ordered)\n", + "order_status" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "uc803yEKgnoL", + "outputId": "aa5a0fda-13d6-47cc-b261-6d5d9ce4cb8c" + }, + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Total number of products in the inventory is: 5\n", + "Total number of products ordered is: 3\n", + "percentage ordered: 60.0\n" + ] + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(5, 60.0)" + ] + }, + "metadata": {}, + "execution_count": 7 + } + ] + }, + { + "cell_type": "code", + "source": [ + "total_quantity_available=sum(inventory.values()) #calculating total quantity of products available\n", + "total_quantity_available" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "hgsO5XFXgrck", + "outputId": "0999318c-a6cd-4e69-edc1-22ab3bddc6d3" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "110" + ] + }, + "metadata": {}, + "execution_count": 8 + } + ] + }, + { + "cell_type": "code", + "source": [ + "inventory={product:quantity-1 for product, quantity in inventory.items()} #to display the quantity reduced by 1\n", + "print(inventory)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "n3_ieZRDgu3H", + "outputId": "38403258-07b6-41fa-c492-9ee5f76aed6a" + }, + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "{'t-shirt': 9, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 9}\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "keys=inventory.keys() #to display seperate list of product and quantity\n", + "values=inventory.values()\n", + "print(keys)\n", + "print(values)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "wpK7CNGcgyWC", + "outputId": "55375d87-599b-4ee2-bb83-e386b75b6a7f" + }, + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "dict_keys(['t-shirt', 'mug', 'hat', 'book', 'keychain'])\n", + "dict_values([9, 19, 29, 39, 9])\n" + ] + } + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.13" + }, + "colab": { + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file