diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..ef54b751 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -1,54 +1,230 @@ { "cells": [ { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, + "cell_type": "code", + "execution_count": 35, + "id": "7b4be6cf-fbfb-4ec7-b73f-d9285956d910", + "metadata": {}, + "outputs": [], "source": [ - "# Lab | Data Structures " + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 36, + "id": "3805edc9-cdb6-4488-9676-979969015f0d", "metadata": {}, + "outputs": [], "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", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "a0521e39-dc55-4c85-8e9c-95334a0d3d8c", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "How many t-shirts are there in the warehouse? 50\n", + "How many mugs are there in the warehouse? 40\n", + "How many hats are there in the warehouse? 30\n", + "How many books are there in the warehouse? 60\n", + "How many keychains are there in the warehouse? 45\n" + ] + } + ], + "source": [ + "inventory['t-shirt'] = int(input('How many t-shirts are there in the warehouse?'))\n", + "inventory['mug'] = int(input('How many mugs are there in the warehouse?'))\n", + "inventory['hat'] = int(input('How many hats are there in the warehouse?'))\n", + "inventory['book'] = int(input('How many books are there in the warehouse?'))\n", + "inventory['keychain'] = int(input('How many keychains are there in the warehouse?'))" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "cca3f5c7-0fa4-4a30-8708-a66f5ec4b4e1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 50, 'mug': 40, 'hat': 30, 'book': 60, 'keychain': 45}\n" + ] + } + ], + "source": [ + "print(\"Inventory:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "5e7ab553-e7c8-4b5f-a083-283e10e9b377", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "8de79e2a-910c-4cb7-b414-291b1d2ee614", + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "What is product 1 in the customer order ? mug\n", + "What is product 2 in the customer order ? book\n", + "What is product 3 in the customer order ? t-shirt\n" + ] + } + ], + "source": [ + "product_1 = input('What is product 1 in the customer order ? ')\n", + "customer_orders.add(product_1)\n", "\n", - "10. Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "product_2 = input('What is product 2 in the customer order ? ')\n", + "customer_orders.add(product_2)\n", "\n", - "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " + "product_3 = input('What is product 3 in the customer order ? ')\n", + "customer_orders.add(product_3)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "1c3764ea-c90a-45d6-8c10-b8d2b9b6ab3a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer Orders: {'book', 'mug', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(\"Customer Orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "d4d39323-eb1b-46c6-8df1-21800384d013", + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "91221d4b-f912-4f53-873a-e088d49e1441", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "82c57f07-57be-4d98-ad9e-a0c065117080", + "metadata": {}, + "outputs": [], + "source": [ + "percentage_of_products_ordered = (len(customer_orders) / len(products))*100" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "b72378ba-8cca-43a6-9000-788d73872a7a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60 %\n" + ] + } + ], + "source": [ + "print(int(percentage_of_products_ordered),'%')" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "3ea2a193-f136-4c74-84fd-eb857dbdb7d5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60 %\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", int(percentage_of_products_ordered), \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "e9047728-48eb-49c4-aa87-b994436a9ad9", + "metadata": {}, + "outputs": [], + "source": [ + "inventory[product_1] -= 1\n", + "inventory[product_2] -= 1\n", + "inventory[product_3] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "d8585714-3b5c-4553-bbe1-042409a675d6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Inventory: {'t-shirt': 49, 'mug': 39, 'hat': 30, 'book': 59, 'keychain': 45}\n" + ] + } + ], + "source": [ + "print(\"Inventory:\", inventory)" ] } ], @@ -68,9 +244,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.3" } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 }