diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store 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..999e59f7 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,349 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "#test GitHub" + ] + }, + { + "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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please add the quantity for t-shirt 5\n", + "Please add the quantity for mug 9\n", + "Please add the quantity for hat 7\n", + "Please add the quantity for book 4\n", + "Please add the quantity for keychain 6\n" + ] + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(\"Please add the quantity for \" + product))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 9, 'hat': 7, 'book': 4, 'keychain': 6}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter your order here: book\n", + "Please enter your order here: hat\n", + "Please enter your order here: mug\n" + ] + } + ], + "source": [ + "print(\"Available products:\", products)\n", + "customer_orders = set()\n", + "for i in range(3):\n", + " product = input(\"Please enter your order here: \")\n", + " customer_orders.add(product)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n" + ] + } + ], + "source": [ + "percentage_products_ordered = (total_products_ordered / len(products))*100\n", + "print (percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 60.0)\n" + ] + } + ], + "source": [ + "order_status = (total_products_ordered, percentage_products_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.0%\n" + ] + } + ], + "source": [ + "print (\"Order Statistics:\")\n", + "print(\"Total products ordered:\", total_products_ordered)\n", + "print(\"Percentage of products ordered:\", str(percentage_products_ordered) + \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 9, 'hat': 7, 'book': 4, 'keychain': 6}\n" + ] + } + ], + "source": [ + "print(inventory)\n", + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 8, 'hat': 6, 'book': 3, 'keychain': 6}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt : 5\n", + "mug : 8\n", + "hat : 6\n", + "book : 3\n", + "keychain : 6\n" + ] + } + ], + "source": [ + "for product in inventory:\n", + " print (product, \":\", inventory[product])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..999e59f7 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -9,6 +9,19 @@ "# Lab | Data Structures " ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "#test GitHub" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -50,6 +63,266 @@ "\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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please add the quantity for t-shirt 5\n", + "Please add the quantity for mug 9\n", + "Please add the quantity for hat 7\n", + "Please add the quantity for book 4\n", + "Please add the quantity for keychain 6\n" + ] + } + ], + "source": [ + "for product in products:\n", + " quantity = int(input(\"Please add the quantity for \" + product))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 9, 'hat': 7, 'book': 4, 'keychain': 6}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Available products: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter your order here: book\n", + "Please enter your order here: hat\n", + "Please enter your order here: mug\n" + ] + } + ], + "source": [ + "print(\"Available products:\", products)\n", + "customer_orders = set()\n", + "for i in range(3):\n", + " product = input(\"Please enter your order here: \")\n", + " customer_orders.add(product)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'hat', 'mug'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "total_products_ordered = len(customer_orders)\n", + "print(total_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n" + ] + } + ], + "source": [ + "percentage_products_ordered = (total_products_ordered / len(products))*100\n", + "print (percentage_products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(3, 60.0)\n" + ] + } + ], + "source": [ + "order_status = (total_products_ordered, percentage_products_ordered)\n", + "print(order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total products ordered: 3\n", + "Percentage of products ordered: 60.0%\n" + ] + } + ], + "source": [ + "print (\"Order Statistics:\")\n", + "print(\"Total products ordered:\", total_products_ordered)\n", + "print(\"Percentage of products ordered:\", str(percentage_products_ordered) + \"%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5, 'mug': 9, 'hat': 7, 'book': 4, 'keychain': 6}\n" + ] + } + ], + "source": [ + "print(inventory)\n", + "for product in customer_orders:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 5, 'mug': 8, 'hat': 6, 'book': 3, 'keychain': 6}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt : 5\n", + "mug : 8\n", + "hat : 6\n", + "book : 3\n", + "keychain : 6\n" + ] + } + ], + "source": [ + "for product in inventory:\n", + " print (product, \":\", inventory[product])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +341,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,