From d982fcef4cb11fe9e7d5d7daff4b4d72ee0e30b5 Mon Sep 17 00:00:00 2001 From: elbgross Date: Sat, 30 Aug 2025 09:05:33 +0200 Subject: [PATCH 1/2] Lab completed --- lab-data-structures_elbgr.ipynb | 132 +++++++++++++++++++++++++++++++ lab-python-data-structures.ipynb | 40 +++++++++- 2 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 lab-data-structures_elbgr.ipynb diff --git a/lab-data-structures_elbgr.ipynb b/lab-data-structures_elbgr.ipynb new file mode 100644 index 00000000..4d949187 --- /dev/null +++ b/lab-data-structures_elbgr.ipynb @@ -0,0 +1,132 @@ +{ + "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": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 5.0}\n", + "{'t-shirt': 5.0, 'mug': 5.0}\n", + "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0}\n", + "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0, 'book': 5.0}\n", + "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0, 'book': 5.0, 'keychain': 5.0}\n", + "{'keychain', 'hat', 'mug'}\n", + "3\n", + "60.0\n" + ] + } + ], + "source": [ + "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", + "inventory={}\n", + "for product in products:\n", + " quantity=float(input(f\"Please enter the quantity for {product}\"))\n", + " #here we are defining that product is the key on the dictionary and quantity is the value\n", + " inventory[product]=quantity\n", + " print(inventory)\n", + "\n", + "customers_orders=set()\n", + "while len(customers_orders)<3:\n", + " order_product=input(\"Please choose an item from the product list\")\n", + " #Previusly you tried to write \"if is not in\" as you can see the if conditional goes without \"is\"\n", + " if order_product not in products:\n", + " print(\"This product is not available\")\n", + " continue\n", + " if order_product in customers_orders:\n", + " print(\"You already selected this product\")\n", + " continue\n", + " \n", + " customers_orders.add(order_product)\n", + " \n", + "\n", + "print(customers_orders)\n", + "\n", + "#Order statistics:\n", + "total_products_ordered=len(customers_orders)\n", + "print(total_products_ordered)\n", + "percentage_products_ordered=(len(customers_orders)/len(products))*100\n", + "print(percentage_products_ordered)\n", + "\n", + "\n", + "\n", + "\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..096d5637 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,47 @@ "\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": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 6.0}\n", + "{'t-shirt': 6.0, 'mug': 6.0}\n", + "{'t-shirt': 6.0, 'mug': 6.0, 'hat': 6.0}\n", + "{'t-shirt': 6.0, 'mug': 6.0, 'hat': 6.0, 'book': 6.0}\n", + "{'t-shirt': 6.0, 'mug': 6.0, 'hat': 6.0, 'book': 6.0, 'keychain': 6.0}\n" + ] + } + ], + "source": [ + "products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n", + "inventory={}\n", + "for product in products:\n", + " quantity=float(input(f\"Please enter the quantity for {product}\"))\n", + " inventory[product]=quantity\n", + " print(inventory)\n", + "\n", + "customers_orders=set()\n", + "while len(customers_orders)<4:\n", + " order_product=input(\"Please choose an item from the product list\")\n", + " customers_orders.add(order_product)\n", + "\n", + "print(customers_orders)\n", + "\n", + "\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -68,7 +104,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.6" } }, "nbformat": 4, From bdb03288151e2ba1a9c2d2340ec795cc5e2ddccc Mon Sep 17 00:00:00 2001 From: elbgross Date: Sat, 30 Aug 2025 09:26:35 +0200 Subject: [PATCH 2/2] lab modify --- lab-data-structures_elbgr.ipynb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lab-data-structures_elbgr.ipynb b/lab-data-structures_elbgr.ipynb index 4d949187..5f482734 100644 --- a/lab-data-structures_elbgr.ipynb +++ b/lab-data-structures_elbgr.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -65,9 +65,14 @@ "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0}\n", "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0, 'book': 5.0}\n", "{'t-shirt': 5.0, 'mug': 5.0, 'hat': 5.0, 'book': 5.0, 'keychain': 5.0}\n", - "{'keychain', 'hat', 'mug'}\n", + "This product is not available\n", + "This product is not available\n", + "You already selected this product\n", + "You already selected this product\n", + "{'mug', 'keychain', 'hat'}\n", "3\n", - "60.0\n" + "60.0\n", + "{'t-shirt': 4.0, 'mug': 4.0, 'hat': 4.0, 'book': 4.0, 'keychain': 4.0}\n" ] } ], @@ -101,6 +106,15 @@ "print(total_products_ordered)\n", "percentage_products_ordered=(len(customers_orders)/len(products))*100\n", "print(percentage_products_ordered)\n", + "order_status=(total_products_ordered,percentage_products_ordered)\n", + "\n", + "#Substracting one from the quantity\n", + "\n", + "for product in inventory:\n", + " inventory[product]=float(inventory[product])-1\n", + "\n", + "\n", + "print(inventory) \n", "\n", "\n", "\n",