From ebdf36a38ea4d5f646183bd4e8def67b1220bcaa Mon Sep 17 00:00:00 2001 From: Rodrigo Quintiliano Date: Tue, 21 Oct 2025 16:33:43 +0100 Subject: [PATCH 1/2] Rodrigo Quintiliano Lab Day 2 --- ...ab-python-data-structures-checkpoint.ipynb | 278 ++++++++++++++++++ lab-python-data-structures.ipynb | 204 ++++++++++++- 2 files changed, 481 insertions(+), 1 deletion(-) create mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb 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..c99fce25 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,278 @@ +{ + "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. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select quantity of available product: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "t-shirt: 10\n", + "mug: 10\n", + "hat: 10\n", + "book: 10\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "print(\"select quantity of available product: \")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select 3 products that the client wants to order: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product: t-shirt\n", + "Product: mug\n", + "Product: book\n" + ] + } + ], + "source": [ + "print(\"select 3 products that the client wants to order: \")\n", + "for i in range(3):\n", + " order = input(f\"Product: \")\n", + " if order in products:\n", + " customer_orders.add(order)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "customer_orders:\n", + "{'mug', 'book', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(\"\\ncustomer_orders:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 9, 'hat': 10, 'book': 9, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_available = sum(inventory.values())\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 6%\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered:.0f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory:\n", + "t-shirt: 9\n", + "mug: 9\n", + "hat: 10\n", + "book: 9\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(\"\\nUpdated Inventory:\")\n", + "for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity}\")" + ] + } + ], + "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..c99fce25 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,208 @@ "\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": 5, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 96, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select quantity of available product: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "t-shirt: 10\n", + "mug: 10\n", + "hat: 10\n", + "book: 10\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "print(\"select quantity of available product: \")\n", + "for product in products:\n", + " quantity = int(input(f\"{product}: \"))\n", + " inventory[product] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "select 3 products that the client wants to order: \n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Product: t-shirt\n", + "Product: mug\n", + "Product: book\n" + ] + } + ], + "source": [ + "print(\"select 3 products that the client wants to order: \")\n", + "for i in range(3):\n", + " order = input(f\"Product: \")\n", + " if order in products:\n", + " customer_orders.add(order)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "customer_orders:\n", + "{'mug', 'book', 't-shirt'}\n" + ] + } + ], + "source": [ + "print(\"\\ncustomer_orders:\")\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 9, 'hat': 10, 'book': 9, 'keychain': 10}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [], + "source": [ + "total_products_available = sum(inventory.values())\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_ordered = (total_products_ordered / total_products_available) * 100" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 6%\n" + ] + } + ], + "source": [ + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_ordered:.0f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory:\n", + "t-shirt: 9\n", + "mug: 9\n", + "hat: 10\n", + "book: 9\n", + "keychain: 10\n" + ] + } + ], + "source": [ + "for product in customer_orders:\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(\"\\nUpdated Inventory:\")\n", + "for item, quantity in inventory.items():\n", + " print(f\"{item}: {quantity}\")" + ] } ], "metadata": { @@ -68,7 +270,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 35a537eb10a0393ee4d6a9dc2d1d6ba2322848ec Mon Sep 17 00:00:00 2001 From: Rodrigo Quintiliano Date: Tue, 21 Oct 2025 16:36:42 +0100 Subject: [PATCH 2/2] Delete .ipynb_checkpoints directory --- ...ab-python-data-structures-checkpoint.ipynb | 278 ------------------ 1 file changed, 278 deletions(-) delete mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb deleted file mode 100644 index c99fce25..00000000 --- a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb +++ /dev/null @@ -1,278 +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. " - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n" - ] - }, - { - "cell_type": "code", - "execution_count": 95, - "metadata": {}, - "outputs": [], - "source": [ - "inventory = {}" - ] - }, - { - "cell_type": "code", - "execution_count": 96, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "select quantity of available product: \n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "t-shirt: 10\n", - "mug: 10\n", - "hat: 10\n", - "book: 10\n", - "keychain: 10\n" - ] - } - ], - "source": [ - "print(\"select quantity of available product: \")\n", - "for product in products:\n", - " quantity = int(input(f\"{product}: \"))\n", - " inventory[product] = quantity" - ] - }, - { - "cell_type": "code", - "execution_count": 97, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" - ] - } - ], - "source": [ - "print(inventory)" - ] - }, - { - "cell_type": "code", - "execution_count": 98, - "metadata": {}, - "outputs": [], - "source": [ - "customer_orders = set()" - ] - }, - { - "cell_type": "code", - "execution_count": 99, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "select 3 products that the client wants to order: \n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Product: t-shirt\n", - "Product: mug\n", - "Product: book\n" - ] - } - ], - "source": [ - "print(\"select 3 products that the client wants to order: \")\n", - "for i in range(3):\n", - " order = input(f\"Product: \")\n", - " if order in products:\n", - " customer_orders.add(order)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 104, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "customer_orders:\n", - "{'mug', 'book', 't-shirt'}\n" - ] - } - ], - "source": [ - "print(\"\\ncustomer_orders:\")\n", - "print(customer_orders)" - ] - }, - { - "cell_type": "code", - "execution_count": 136, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 9, 'mug': 9, 'hat': 10, 'book': 9, 'keychain': 10}\n" - ] - } - ], - "source": [ - "print(inventory)" - ] - }, - { - "cell_type": "code", - "execution_count": 138, - "metadata": {}, - "outputs": [], - "source": [ - "total_products_available = sum(inventory.values())\n", - "total_products_ordered = len(customer_orders)\n", - "percentage_ordered = (total_products_ordered / total_products_available) * 100" - ] - }, - { - "cell_type": "code", - "execution_count": 140, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Order Statistics:\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 6%\n" - ] - } - ], - "source": [ - "print(\"Order Statistics:\")\n", - "print(f\"Total Products Ordered: {total_products_ordered}\")\n", - "print(f\"Percentage of Products Ordered: {percentage_ordered:.0f}%\")" - ] - }, - { - "cell_type": "code", - "execution_count": 123, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Updated Inventory:\n", - "t-shirt: 9\n", - "mug: 9\n", - "hat: 10\n", - "book: 9\n", - "keychain: 10\n" - ] - } - ], - "source": [ - "for product in customer_orders:\n", - " if product in inventory and inventory[product] > 0:\n", - " inventory[product] -= 1\n", - "print(\"\\nUpdated Inventory:\")\n", - "for item, quantity in inventory.items():\n", - " print(f\"{item}: {quantity}\")" - ] - } - ], - "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 -}