From 78f28712b037b7d3bd58211c729f0189615939d9 Mon Sep 17 00:00:00 2001 From: titijoli2-ai Date: Mon, 25 May 2026 17:34:45 +0200 Subject: [PATCH 1/2] Add files via upload --- Tina's_lab-python-data-structures.ipynb | 312 ++++++++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 Tina's_lab-python-data-structures.ipynb diff --git a/Tina's_lab-python-data-structures.ipynb b/Tina's_lab-python-data-structures.ipynb new file mode 100644 index 00000000..d8b73f1d --- /dev/null +++ b/Tina's_lab-python-data-structures.ipynb @@ -0,0 +1,312 @@ +{ + "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": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "1. \n", + "products_list=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print (products_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 31\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 07\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7, 'keychain': 10}\n" + ] + } + ], + "source": [ + "2.\n", + "inventory_dict = {}\n", + "3.\n", + "for product in products_list:\n", + " value = int(input(\"Please, enter the quantity of each product in product_list\"))\n", + " inventory_dict[product] = value\n", + " print (inventory_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "4.\n", + "customer_orders_set = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need keychain\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'hat'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'hat', 'mug'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain', 'hat', 'mug'}\n" + ] + } + ], + "source": [ + "5. 6.\n", + "for product in range(3):\n", + " item = input(\"Please enter 3 products you need\")\n", + " customer_orders_set.add(item)\n", + " print(customer_orders_set)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "7.\n", + "total_products_ordered = len(customer_orders_set)\n", + "percentage_ordered = (total_products_ordered / len(products_list)) * 100\n", + "\n", + "8.\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 30, 'mug': 12, 'hat': 25, 'book': 7, 'keychain': 10}\n", + "{'t-shirt': 30, 'mug': 11, 'hat': 25, 'book': 7, 'keychain': 10}\n", + "{'t-shirt': 30, 'mug': 11, 'hat': 24, 'book': 7, 'keychain': 10}\n", + "{'t-shirt': 30, 'mug': 11, 'hat': 24, 'book': 6, 'keychain': 10}\n", + "{'t-shirt': 30, 'mug': 11, 'hat': 24, 'book': 6, 'keychain': 9}\n" + ] + } + ], + "source": [ + "9.\n", + "for product in inventory_dict:\n", + " inventory_dict[product]-=1\n", + "\n", + " 10.\n", + " print(inventory_dict)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.11" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 4daf48e233ad7816a35a467277b7424b3e7f170c Mon Sep 17 00:00:00 2001 From: titijoli2-ai Date: Mon, 25 May 2026 19:48:38 +0200 Subject: [PATCH 2/2] Add files via upload --- lab-python-data-structures.ipynb | 253 ++++++++++++++++++++++++++++++- 1 file changed, 252 insertions(+), 1 deletion(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..5e8b41fc 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,6 +57,250 @@ "\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": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], + "source": [ + "1. \n", + "products_list=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print (products_list)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 31\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 12\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 07\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please, enter the quantity of each product in product_list 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 31, 'mug': 12, 'hat': 25, 'book': 7, 'keychain': 10}\n" + ] + } + ], + "source": [ + "2.\n", + "inventory_dict = {}\n", + "3.\n", + "for product in products_list:\n", + " value = int(input(\"Please, enter the quantity of each product in product_list\"))\n", + " inventory_dict[product] = value\n", + " print (inventory_dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "4.\n", + "customer_orders_set = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need keychain\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'keychain'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need mug\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'keychain'}\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter 3 products you need hat\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'keychain', 'hat'}\n" + ] + } + ], + "source": [ + "5.6.\n", + " \n", + "for product in range(3):\n", + " item = input(\"Please enter 3 products you need\")\n", + " customer_orders_set.add(item)\n", + " print(customer_orders_set)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "7.\n", + "total_products_ordered = len(customer_orders_set)\n", + "percentage_ordered = (total_products_ordered / len(products_list)) * 100\n", + "\n", + "8.\n", + "print(\"Total Products Ordered:\", total_products_ordered)\n", + "print(\"Percentage of Products Ordered:\", percentage_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 29, 'mug': 11, 'hat': 24, 'book': 6, 'keychain': 9}\n", + "{'t-shirt': 29, 'mug': 10, 'hat': 24, 'book': 6, 'keychain': 9}\n", + "{'t-shirt': 29, 'mug': 10, 'hat': 23, 'book': 6, 'keychain': 9}\n", + "{'t-shirt': 29, 'mug': 10, 'hat': 23, 'book': 5, 'keychain': 9}\n", + "{'t-shirt': 29, 'mug': 10, 'hat': 23, 'book': 5, 'keychain': 8}\n" + ] + } + ], + "source": [ + "9.\n", + "\n", + "for product in inventory_dict:\n", + " inventory_dict[product]-=1\n", + "10.\n", + " print(inventory_dict)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -68,7 +319,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.11" } }, "nbformat": 4,