From 5f317be2584d7d9083217ec6b50b3aeed4fe6be8 Mon Sep 17 00:00:00 2001 From: Sofija Date: Mon, 14 Sep 2026 17:55:44 +0200 Subject: [PATCH 1/2] Solved lab --- ...ab-python-data-structures-checkpoint.ipynb | 383 ++++++++++++++++++ lab-python-data-structures.ipynb | 309 +++++++++++++- 2 files changed, 691 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..1f76c4c0 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,383 @@ +{ + "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": "markdown", + "metadata": {}, + "source": [ + "\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." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the number of t-shirt: 2\n", + "Enter the number of mug: 3\n", + "Enter the number of hat: 4\n", + "Enter the number of book: 56\n", + "Enter the number of keychain: 8\n" + ] + } + ], + "source": [ + "for item in products:\n", + " quantity = int(input(f\"Enter the number of {item}: \"))\n", + " inventory[item] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 56, 'keychain': 8}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: book\n", + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: keychain\n", + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: mug\n" + ] + } + ], + "source": [ + "for item in range(3):\n", + " order = input(f\"Name 1 product: from {products} list: \")\n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'keychain', 'mug'}" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "total_orders = len(customer_orders)\n", + "\n", + "percentage = (total_orders / len(products) * 100)\n", + "\n", + "order_status = (total_orders, percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "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(f\"\"\"Order Statistics:\n", + "Total Products Ordered: {order_status[0]}\n", + "Percentage of Products Ordered: {order_status[1]}%\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 2, 'hat': 4, 'book': 55, 'keychain': 7}" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'keychain', 'mug'}" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_orders:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 1, 'hat': 4, 'book': 54, 'keychain': 6}" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 2\n", + "mug: 1\n", + "hat: 4\n", + "book: 54\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "for keys, values in inventory.items():\n", + " print(f\"{keys}: {values}\")" + ] + } + ], + "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.14.7" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..1f76c4c0 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,6 +50,313 @@ "\n", "Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. " ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\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." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the number of t-shirt: 2\n", + "Enter the number of mug: 3\n", + "Enter the number of hat: 4\n", + "Enter the number of book: 56\n", + "Enter the number of keychain: 8\n" + ] + } + ], + "source": [ + "for item in products:\n", + " quantity = int(input(f\"Enter the number of {item}: \"))\n", + " inventory[item] = quantity" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 56, 'keychain': 8}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: book\n", + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: keychain\n", + "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: mug\n" + ] + } + ], + "source": [ + "for item in range(3):\n", + " order = input(f\"Name 1 product: from {products} list: \")\n", + " customer_orders.add(order)" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'keychain', 'mug'}" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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", + " ```" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [], + "source": [ + "total_orders = len(customer_orders)\n", + "\n", + "percentage = (total_orders / len(products) * 100)\n", + "\n", + "order_status = (total_orders, percentage)" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 60.0)" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "order_status" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "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(f\"\"\"Order Statistics:\n", + "Total Products Ordered: {order_status[0]}\n", + "Percentage of Products Ordered: {order_status[1]}%\"\"\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 2, 'hat': 4, 'book': 55, 'keychain': 7}" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'book', 'keychain', 'mug'}" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [], + "source": [ + "for item in customer_orders:\n", + " inventory[item] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'t-shirt': 2, 'mug': 1, 'hat': 4, 'book': 54, 'keychain': 6}" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 2\n", + "mug: 1\n", + "hat: 4\n", + "book: 54\n", + "keychain: 6\n" + ] + } + ], + "source": [ + "for keys, values in inventory.items():\n", + " print(f\"{keys}: {values}\")" + ] } ], "metadata": { @@ -68,7 +375,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.7" } }, "nbformat": 4, From 78f9ca377046e7b6820a1da93e7555cdbad47ab1 Mon Sep 17 00:00:00 2001 From: Sofija Date: Mon, 14 Sep 2026 17:59:05 +0200 Subject: [PATCH 2/2] Ignore jupyter checkpoint folder --- .gitignore | 1 + ...ab-python-data-structures-checkpoint.ipynb | 383 ------------------ 2 files changed, 1 insertion(+), 383 deletions(-) create mode 100644 .gitignore delete mode 100644 .ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..763513e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints 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 1f76c4c0..00000000 --- a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb +++ /dev/null @@ -1,383 +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": "markdown", - "metadata": {}, - "source": [ - "\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." - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [], - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [], - "source": [ - "inventory = {}" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter the number of t-shirt: 2\n", - "Enter the number of mug: 3\n", - "Enter the number of hat: 4\n", - "Enter the number of book: 56\n", - "Enter the number of keychain: 8\n" - ] - } - ], - "source": [ - "for item in products:\n", - " quantity = int(input(f\"Enter the number of {item}: \"))\n", - " inventory[item] = quantity" - ] - }, - { - "cell_type": "code", - "execution_count": 38, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 56, 'keychain': 8}" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "inventory" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "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." - ] - }, - { - "cell_type": "code", - "execution_count": 39, - "metadata": {}, - "outputs": [], - "source": [ - "customer_orders = set()" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": {}, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: book\n", - "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: keychain\n", - "Name 1 product: from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] list: mug\n" - ] - } - ], - "source": [ - "for item in range(3):\n", - " order = input(f\"Name 1 product: from {products} list: \")\n", - " customer_orders.add(order)" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'book', 'keychain', 'mug'}" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "customer_orders" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "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", - " ```" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": {}, - "outputs": [], - "source": [ - "total_orders = len(customer_orders)\n", - "\n", - "percentage = (total_orders / len(products) * 100)\n", - "\n", - "order_status = (total_orders, percentage)" - ] - }, - { - "cell_type": "code", - "execution_count": 68, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(3, 60.0)" - ] - }, - "execution_count": 68, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "order_status" - ] - }, - { - "cell_type": "code", - "execution_count": 69, - "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(f\"\"\"Order Statistics:\n", - "Total Products Ordered: {order_status[0]}\n", - "Percentage of Products Ordered: {order_status[1]}%\"\"\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "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." - ] - }, - { - "cell_type": "code", - "execution_count": 70, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'t-shirt': 2, 'mug': 2, 'hat': 4, 'book': 55, 'keychain': 7}" - ] - }, - "execution_count": 70, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "inventory" - ] - }, - { - "cell_type": "code", - "execution_count": 71, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'book', 'keychain', 'mug'}" - ] - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "customer_orders" - ] - }, - { - "cell_type": "code", - "execution_count": 72, - "metadata": {}, - "outputs": [], - "source": [ - "for item in customer_orders:\n", - " inventory[item] -= 1" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'t-shirt': 2, 'mug': 1, 'hat': 4, 'book': 54, 'keychain': 6}" - ] - }, - "execution_count": 73, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "inventory" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "t-shirt: 2\n", - "mug: 1\n", - "hat: 4\n", - "book: 54\n", - "keychain: 6\n" - ] - } - ], - "source": [ - "for keys, values in inventory.items():\n", - " print(f\"{keys}: {values}\")" - ] - } - ], - "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.14.7" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}