From 49d5315e4ef8d1691a4eb4b35ff30e03d43e3c83 Mon Sep 17 00:00:00 2001 From: Anna Igumnova Date: Fri, 17 Oct 2025 20:24:30 +0200 Subject: [PATCH 1/3] Added first three steps of the exercise --- ...ab-python-data-structures-checkpoint.ipynb | 113 ++++++++++++++++++ lab-python-data-structures.ipynb | 43 ++++++- 2 files changed, 153 insertions(+), 3 deletions(-) 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..2e432c36 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,113 @@ +{ + "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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the amount of t-shirts: 2\n", + "Enter the amount of mugs: 4\n", + "Enter the amount of hats: 7\n", + "Enter the amount of books: 3\n", + "Enter the amount of keychains: 9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '2', 'mug': '4', 'hat': '7', 'book': '3', 'keychain': '9'}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {products[0] : input(\"Enter the amount of t-shirts: \"), products[1] : input(\"Enter the amount of mugs: \"), products[2] : input(\"Enter the amount of hats: \"), products[3] : input(\"Enter the amount of books: \"), products[4] : input(\"Enter the amount of keychains: \")}\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..2e432c36 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,50 @@ "\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": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the amount of t-shirts: 2\n", + "Enter the amount of mugs: 4\n", + "Enter the amount of hats: 7\n", + "Enter the amount of books: 3\n", + "Enter the amount of keychains: 9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': '2', 'mug': '4', 'hat': '7', 'book': '3', 'keychain': '9'}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {products[0] : input(\"Enter the amount of t-shirts: \"), products[1] : input(\"Enter the amount of mugs: \"), products[2] : input(\"Enter the amount of hats: \"), products[3] : input(\"Enter the amount of books: \"), products[4] : input(\"Enter the amount of keychains: \")}\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "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 +105,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 3567c5d21ddc76ff667cc5071313ad63826b1a8f Mon Sep 17 00:00:00 2001 From: Anna Igumnova Date: Sun, 19 Oct 2025 20:45:18 +0200 Subject: [PATCH 2/3] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 141 +++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 15 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 2e432c36..a5363588 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -51,49 +51,160 @@ "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": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {} # empty dictionary" + ] + }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { - "name": "stdin", + "name": "stdout", "output_type": "stream", "text": [ - "Enter the amount of t-shirts: 2\n", - "Enter the amount of mugs: 4\n", - "Enter the amount of hats: 7\n", - "Enter the amount of books: 3\n", - "Enter the amount of keychains: 9\n" + "{'t-shirt': 3, 'mug': 5, 'hat': 7, 'book': 8, 'keychain': 6}\n" ] - }, + } + ], + "source": [ + "inventory[products[0]] = int(input(\"Enter the amount of t-shirts: \"))\n", + "inventory[products[1]] = int(input(\"Enter the amount of mugs: \"))\n", + "inventory[products[2]] = int(input(\"Enter the amount of hats: \"))\n", + "inventory[products[3]] = int(input(\"Enter the amount of books: \"))\n", + "inventory[products[4]] = int(input(\"Enter the amount of keychains: \"))\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'t-shirt': '2', 'mug': '4', 'hat': '7', 'book': '3', 'keychain': '9'}\n" + "Your order: {'book', 'mug', 'hat'}\n" ] } ], "source": [ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "inventory = {products[0] : input(\"Enter the amount of t-shirts: \"), products[1] : input(\"Enter the amount of mugs: \"), products[2] : input(\"Enter the amount of hats: \"), products[3] : input(\"Enter the amount of books: \"), products[4] : input(\"Enter the amount of keychains: \")}\n", - "print(inventory)" + "customer_orders = set() # empty set\n", + "for i in range(3):\n", + " product = input(\"Enter the product to the order: \")\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"product not found, try again\")\n", + "print(\"Your order: \", customer_orders)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "products_ordered = len(customer_orders)\n", + "print(products_ordered)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "avaliable_products = len(products)\n", + "print(avaliable_products)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0\n" + ] + } + ], + "source": [ + "percentage = (products_ordered/avaliable_products)*100\n", + "print(percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order status: ('ordered products:', 3, 'products avaliable:', 5)\n" + ] + } + ], + "source": [ + "order_status = (\"ordered products:\", products_ordered, \"products avaliable:\", avaliable_products)\n", + "print(\"Order status: \", order_status)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: Total Products Ordered: 3 Percentage of Products Ordered: 60.0\n" + ] + } + ], + "source": [ + "print(\"Order Statistics: \",\n", + " \"Total Products Ordered: \", products_ordered, \" \", \n", + " \"Percentage of Products Ordered: \", percentage )" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:base] *", + "display_name": "base", "language": "python", - "name": "conda-base-py" + "name": "python3" }, "language_info": { "codemirror_mode": { From 90871823f8dc70e13ff693e17b04546cfe98d57f Mon Sep 17 00:00:00 2001 From: Anna Igumnova Date: Sun, 19 Oct 2025 21:07:35 +0200 Subject: [PATCH 3/3] finished lab --- lab-python-data-structures.ipynb | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index a5363588..2cbc723f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -198,6 +198,101 @@ " \"Total Products Ordered: \", products_ordered, \" \", \n", " \"Percentage of Products Ordered: \", percentage )" ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 5, 'hat': 7, 'book': 8, 'keychain': 6}\n" + ] + } + ], + "source": [ + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'book', 'mug', 'hat'}\n" + ] + } + ], + "source": [ + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['t-shirt', 'mug', 'hat', 'book', 'keychain'])\n" + ] + } + ], + "source": [ + "print(inventory.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 4, 'hat': 6, 'book': 7, 'keychain': 6}\n" + ] + } + ], + "source": [ + "for product in customer_orders: # task 9 - update the inventory list\n", + " if product in inventory and inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated inventory:\n", + "t-shirt: 3\n", + "mug: 4\n", + "hat: 6\n", + "book: 7\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "print(\"Updated inventory:\")\n", + "for position, amount in inventory.items():\n", + " print(position + \": \" + str(amount))" + ] } ], "metadata": {