diff --git a/.ipynb_checkpoints/lab-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-data-structures-checkpoint.ipynb new file mode 100644 index 00000000..169ffa73 --- /dev/null +++ b/.ipynb_checkpoints/lab-data-structures-checkpoint.ipynb @@ -0,0 +1,270 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "9609ab30-a065-4c58-9f08-421931bc6e1e", + "metadata": {}, + "outputs": [], + "source": [ + "products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7ee2f55b-55ee-4fd0-ac42-fcfb36906f05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c3216fbf-fd4c-437c-aba6-3a575dda224a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(products)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d9f99365-5d23-41ba-8f5e-396fc37b46cb", + "metadata": {}, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "92a3f184-355e-477f-9cdd-21b666a046c2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter the quantity for each product:\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Quantity of t-shirt: 5\n", + "Quantity of mug: 6\n", + "Quantity of hat: 7\n", + "Quantity of book: 8\n", + "Quantity of keychain: 9\n" + ] + } + ], + "source": [ + "print(\"Please enter the quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"Quantity of {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "651d46f7-9b9f-4575-9e99-7b120cd002f4", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders=set()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "31ec7061-11cf-4919-a8c2-ff9890dcfaf6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter three products the customer wants to order:\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product 1: hat\n", + "Product 2: book\n", + "Product 3: mug\n" + ] + } + ], + "source": [ + "print(\"Please enter three products the customer wants to order:\")\n", + "for i in range(3):\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " while order not in products:\n", + " print(\"Invalid product, please choose from:\", products)\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " \n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "6542cad8-c1f9-4169-8ea8-2fb1fe7afa1f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'book', 'mug'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "f98e9f8b-9b19-4a7c-97c3-7e49bfdc1add", + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "dd653a4c-284c-4e20-ab43-d31e916ed9cd", + "metadata": {}, + "outputs": [], + "source": [ + "percentage_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "823ce3cb-96f4-455d-bb0c-0289d206e5d5", + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "45d28cf3-2b4a-42b0-8667-c26bf90b9f4b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "46441365-7771-4fe4-95f8-87eaaddaee3c", + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "820bff22-e3a0-42c6-a0f2-15e0e8651ae7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 5\n", + "mug: 5\n", + "hat: 6\n", + "book: 7\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6f9c5ac-a460-4b56-9aa3-efaba468aa69", + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} 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..5b3ce9e0 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,76 @@ +{ + "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-data-structures.ipynb b/lab-data-structures.ipynb new file mode 100644 index 00000000..169ffa73 --- /dev/null +++ b/lab-data-structures.ipynb @@ -0,0 +1,270 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "9609ab30-a065-4c58-9f08-421931bc6e1e", + "metadata": {}, + "outputs": [], + "source": [ + "products= [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7ee2f55b-55ee-4fd0-ac42-fcfb36906f05", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "print(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "c3216fbf-fd4c-437c-aba6-3a575dda224a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "list" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(products)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "d9f99365-5d23-41ba-8f5e-396fc37b46cb", + "metadata": {}, + "outputs": [], + "source": [ + "inventory={}" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "92a3f184-355e-477f-9cdd-21b666a046c2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter the quantity for each product:\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Quantity of t-shirt: 5\n", + "Quantity of mug: 6\n", + "Quantity of hat: 7\n", + "Quantity of book: 8\n", + "Quantity of keychain: 9\n" + ] + } + ], + "source": [ + "print(\"Please enter the quantity for each product:\")\n", + "for product in products:\n", + " quantity = int(input(f\"Quantity of {product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "651d46f7-9b9f-4575-9e99-7b120cd002f4", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders=set()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "31ec7061-11cf-4919-a8c2-ff9890dcfaf6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Please enter three products the customer wants to order:\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product 1: hat\n", + "Product 2: book\n", + "Product 3: mug\n" + ] + } + ], + "source": [ + "print(\"Please enter three products the customer wants to order:\")\n", + "for i in range(3):\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " while order not in products:\n", + " print(\"Invalid product, please choose from:\", products)\n", + " order = input(f\"Product {i+1}: \").strip().lower()\n", + " \n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "6542cad8-c1f9-4169-8ea8-2fb1fe7afa1f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'book', 'mug'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "f98e9f8b-9b19-4a7c-97c3-7e49bfdc1add", + "metadata": {}, + "outputs": [], + "source": [ + "total_products_ordered = len(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "dd653a4c-284c-4e20-ab43-d31e916ed9cd", + "metadata": {}, + "outputs": [], + "source": [ + "percentage_ordered = (total_products_ordered / len(products)) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "823ce3cb-96f4-455d-bb0c-0289d206e5d5", + "metadata": {}, + "outputs": [], + "source": [ + "order_status = (total_products_ordered, percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "45d28cf3-2b4a-42b0-8667-c26bf90b9f4b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "print(f\"Total Products Ordered: {order_status[0]}\")\n", + "print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "46441365-7771-4fe4-95f8-87eaaddaee3c", + "metadata": {}, + "outputs": [], + "source": [ + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "820bff22-e3a0-42c6-a0f2-15e0e8651ae7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 5\n", + "mug: 5\n", + "hat: 6\n", + "book: 7\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d6f9c5ac-a460-4b56-9aa3-efaba468aa69", + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1fdb40d2 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -54,9 +54,9 @@ ], "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 +68,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,