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..d26dfbc6 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,219 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": 37, + "metadata": {}, + "outputs": [], + "source": [ + "# Creating a list\n", + "products = [\"t-shirt\", \"mug\",\"hat\", \"book\", \"keychain\"]\n", + "# Creating an empty dictionary\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter key: t-shirt\n", + "Enter value: 4\n", + "Enter key: mug\n", + "Enter value: 3\n", + "Enter key: hat\n", + "Enter value: 2\n", + "Enter key: book\n", + "Enter value: 5\n", + "Enter key: keychain\n", + "Enter value: 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 4, 'mug': 3, 'hat': 2, 'book': 5, 'keychain': 2}\n" + ] + } + ], + "source": [ + "# Input the quanitiy of each product and show the content of the inventory\n", + "inventory = {input(\"Enter key: \"): int(input(\"Enter value: \")) for product in products}\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "enter the product1 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): mug\n", + "enter the product2 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): hat\n", + "enter the product3 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer orders are: {'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "# Input the name of the products and add them to customer_orders set\n", + "customer_orders= set()\n", + "for i in range(3):\n", + " value = input(f\"enter the product{i + 1} (chose from {products}): \")\n", + " customer_orders.add(value)\n", + "print (\"customer orders are: \", customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 27.27272727272727 %\n" + ] + } + ], + "source": [ + "# Calculate the order statistics and print them:\n", + "total_products_ordered=int(len(customer_orders))\n", + "percentage_of_products_ordered = (total_products_ordered/sum(inventory.values())) * 100\n", + "order_status=(total_products_ordered,percentage_of_products_ordered)\n", + "print(\"Order Statistics\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated t-shirt: 2 left\n", + "Updated mug: 1 left\n", + "Updated hat: 0 left\n", + "Updated book: 3 left\n", + "Updated keychain: 0 left\n" + ] + } + ], + "source": [ + "# Update the inventory\n", + "for quantity in inventory:\n", + " inventory[quantity] = inventory[quantity]-1\n", + " print (f\"Updated {quantity}: {inventory[quantity]} left\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-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.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..d26dfbc6 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -9,6 +9,13 @@ "# Lab | Data Structures " ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -50,13 +57,149 @@ "\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": 37, + "metadata": {}, + "outputs": [], + "source": [ + "# Creating a list\n", + "products = [\"t-shirt\", \"mug\",\"hat\", \"book\", \"keychain\"]\n", + "# Creating an empty dictionary\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter key: t-shirt\n", + "Enter value: 4\n", + "Enter key: mug\n", + "Enter value: 3\n", + "Enter key: hat\n", + "Enter value: 2\n", + "Enter key: book\n", + "Enter value: 5\n", + "Enter key: keychain\n", + "Enter value: 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 4, 'mug': 3, 'hat': 2, 'book': 5, 'keychain': 2}\n" + ] + } + ], + "source": [ + "# Input the quanitiy of each product and show the content of the inventory\n", + "inventory = {input(\"Enter key: \"): int(input(\"Enter value: \")) for product in products}\n", + "print (inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "enter the product1 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): mug\n", + "enter the product2 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): hat\n", + "enter the product3 (chose from ['t-shirt', 'mug', 'hat', 'book', 'keychain']): book\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "customer orders are: {'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "# Input the name of the products and add them to customer_orders set\n", + "customer_orders= set()\n", + "for i in range(3):\n", + " value = input(f\"enter the product{i + 1} (chose from {products}): \")\n", + " customer_orders.add(value)\n", + "print (\"customer orders are: \", customer_orders) " + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 27.27272727272727 %\n" + ] + } + ], + "source": [ + "# Calculate the order statistics and print them:\n", + "total_products_ordered=int(len(customer_orders))\n", + "percentage_of_products_ordered = (total_products_ordered/sum(inventory.values())) * 100\n", + "order_status=(total_products_ordered,percentage_of_products_ordered)\n", + "print(\"Order Statistics\")\n", + "print(\"Total Products Ordered:\", order_status[0])\n", + "print(\"Percentage of Products Ordered:\", order_status[1], \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated t-shirt: 2 left\n", + "Updated mug: 1 left\n", + "Updated hat: 0 left\n", + "Updated book: 3 left\n", + "Updated keychain: 0 left\n" + ] + } + ], + "source": [ + "# Update the inventory\n", + "for quantity in inventory:\n", + " inventory[quantity] = inventory[quantity]-1\n", + " print (f\"Updated {quantity}: {inventory[quantity]} left\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:base] *", "language": "python", - "name": "python3" + "name": "conda-base-py" }, "language_info": { "codemirror_mode": { @@ -68,7 +211,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,