From 1fd72ce033f26410e342cb80d7716a7d5be4d88c Mon Sep 17 00:00:00 2001 From: Antonio Gouveia Date: Fri, 29 Aug 2025 11:15:43 +0100 Subject: [PATCH 1/2] data structures lab solution version1 --- ...ab-python-data-structures-checkpoint.ipynb | 308 ++++++++++++++++++ lab-python-data-structures.ipynb | 238 +++++++++++++- 2 files changed, 543 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..5d77f764 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,308 @@ +{ + "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": 100, + "metadata": {}, + "outputs": [], + "source": [ + "# 1 - Define a list called products that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [], + "source": [ + "# 2 - Create an empty dictionary called inventory.\n", + "\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter the quantity of 't-shirt' available in the inventory: 10\n", + "Please enter the quantity of 'mug' available in the inventory: 10\n", + "Please enter the quantity of 'hat' available in the inventory: 10\n", + "Please enter the quantity of 'book' available in the inventory: 10\n", + "Please enter the quantity of 'keychain' available in the inventory: 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "# 3 - Ask the user to input the quantity of each product available in the inventory\n", + "\n", + "for product in products: \n", + " while True:\n", + " quantity = input(f\"Please enter the quantity of '{product}' available in the inventory: \") \n", + " if quantity.isdigit():\n", + " inventory[product] = int(quantity)\n", + " break\n", + " else:\n", + " print(f\"Invalid input for '{product}'. The quantity must be a whole positive number. Try again\")\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "# 4 - Create an empty set called customer_orders.\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PRODUCTS LIST: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product nº 1: mug\n", + "Enter product nº 2: at\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid input. You must enter a product from the list. Try again.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product nº 2: hat\n", + "Enter product nº 3: book\n" + ] + } + ], + "source": [ + "# 5 - Ask the user to input the name of three products that a customer wants to order\n", + "\n", + "print(\"PRODUCTS LIST: \", products)\n", + "print(\"From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\") \n", + "\n", + "while len(customer_orders) < 3:\n", + " order = input(f\"Enter product nº {len(customer_orders)+1}: \").strip().lower()\n", + " \n", + " if order in products:\n", + " if order in customer_orders:\n", + " print(f\"You've already entered '{order.upper()}'. Please enter a different product from the list.\")\n", + " else:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Invalid input. You must enter a product from the list. Try again.\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'book', 'hat'}\n" + ] + } + ], + "source": [ + "# 6 - Print the products in the `customer_orders` set.\n", + "\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0%\n" + ] + } + ], + "source": [ + "# 7- Calculate the following order statistics:\n", + " # 7.1 - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + "total_products_ordered = len(customer_orders)\n", + " # 7.2 - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + "percentage_of_products_ordered = (len(customer_orders)/len(products))*100\n", + "print(f\"{percentage_of_products_ordered}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "# 8 - Print the order statistics:\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_of_products_ordered}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 9, 'hat': 9, 'book': 9, 'keychain': 9}\n" + ] + } + ], + "source": [ + "# 9 - Update the inventory by subtracting 1 from the quantity of each product. \n", + "for product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 9\n", + "mug: 9\n", + "hat: 9\n", + "book: 9\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "# 10 - Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + } + ], + "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..5d77f764 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,13 +50,245 @@ "\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": 100, + "metadata": {}, + "outputs": [], + "source": [ + "# 1 - Define a list called products that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [], + "source": [ + "# 2 - Create an empty dictionary called inventory.\n", + "\n", + "inventory = {}" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Please enter the quantity of 't-shirt' available in the inventory: 10\n", + "Please enter the quantity of 'mug' available in the inventory: 10\n", + "Please enter the quantity of 'hat' available in the inventory: 10\n", + "Please enter the quantity of 'book' available in the inventory: 10\n", + "Please enter the quantity of 'keychain' available in the inventory: 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" + ] + } + ], + "source": [ + "# 3 - Ask the user to input the quantity of each product available in the inventory\n", + "\n", + "for product in products: \n", + " while True:\n", + " quantity = input(f\"Please enter the quantity of '{product}' available in the inventory: \") \n", + " if quantity.isdigit():\n", + " inventory[product] = int(quantity)\n", + " break\n", + " else:\n", + " print(f\"Invalid input for '{product}'. The quantity must be a whole positive number. Try again\")\n", + "print(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "# 4 - Create an empty set called customer_orders.\n", + "customer_orders = set()" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PRODUCTS LIST: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product nº 1: mug\n", + "Enter product nº 2: at\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Invalid input. You must enter a product from the list. Try again.\n" + ] + }, + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter product nº 2: hat\n", + "Enter product nº 3: book\n" + ] + } + ], + "source": [ + "# 5 - Ask the user to input the name of three products that a customer wants to order\n", + "\n", + "print(\"PRODUCTS LIST: \", products)\n", + "print(\"From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\") \n", + "\n", + "while len(customer_orders) < 3:\n", + " order = input(f\"Enter product nº {len(customer_orders)+1}: \").strip().lower()\n", + " \n", + " if order in products:\n", + " if order in customer_orders:\n", + " print(f\"You've already entered '{order.upper()}'. Please enter a different product from the list.\")\n", + " else:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Invalid input. You must enter a product from the list. Try again.\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug', 'book', 'hat'}\n" + ] + } + ], + "source": [ + "# 6 - Print the products in the `customer_orders` set.\n", + "\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60.0%\n" + ] + } + ], + "source": [ + "# 7- Calculate the following order statistics:\n", + " # 7.1 - Total Products Ordered: The total number of products in the `customer_orders` set.\n", + "total_products_ordered = len(customer_orders)\n", + " # 7.2 - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", + "percentage_of_products_ordered = (len(customer_orders)/len(products))*100\n", + "print(f\"{percentage_of_products_ordered}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "# 8 - Print the order statistics:\n", + "print(\"Order Statistics:\")\n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "print(f\"Percentage of Products Ordered: {percentage_of_products_ordered}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 9, 'mug': 9, 'hat': 9, 'book': 9, 'keychain': 9}\n" + ] + } + ], + "source": [ + "# 9 - Update the inventory by subtracting 1 from the quantity of each product. \n", + "for product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "t-shirt: 9\n", + "mug: 9\n", + "hat: 9\n", + "book: 9\n", + "keychain: 9\n" + ] + } + ], + "source": [ + "# 10 - Print the updated inventory, displaying the quantity of each product on separate lines.\n", + "\n", + "for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] } ], "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 +300,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From e8e5d1183a024dde66f6e65f8b12db2bddb6d728 Mon Sep 17 00:00:00 2001 From: Antonio Gouveia Date: Fri, 29 Aug 2025 11:44:12 +0100 Subject: [PATCH 2/2] data structures lab solution version2 --- ...ab-python-data-structures-checkpoint.ipynb | 308 ------------------ 1 file changed, 308 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 5d77f764..00000000 --- a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb +++ /dev/null @@ -1,308 +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": 100, - "metadata": {}, - "outputs": [], - "source": [ - "# 1 - Define a list called products that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "\n", - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 101, - "metadata": {}, - "outputs": [], - "source": [ - "# 2 - Create an empty dictionary called inventory.\n", - "\n", - "inventory = {}" - ] - }, - { - "cell_type": "code", - "execution_count": 102, - "metadata": {}, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Please enter the quantity of 't-shirt' available in the inventory: 10\n", - "Please enter the quantity of 'mug' available in the inventory: 10\n", - "Please enter the quantity of 'hat' available in the inventory: 10\n", - "Please enter the quantity of 'book' available in the inventory: 10\n", - "Please enter the quantity of 'keychain' available in the inventory: 10\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n" - ] - } - ], - "source": [ - "# 3 - Ask the user to input the quantity of each product available in the inventory\n", - "\n", - "for product in products: \n", - " while True:\n", - " quantity = input(f\"Please enter the quantity of '{product}' available in the inventory: \") \n", - " if quantity.isdigit():\n", - " inventory[product] = int(quantity)\n", - " break\n", - " else:\n", - " print(f\"Invalid input for '{product}'. The quantity must be a whole positive number. Try again\")\n", - "print(inventory)" - ] - }, - { - "cell_type": "code", - "execution_count": 103, - "metadata": {}, - "outputs": [], - "source": [ - "# 4 - Create an empty set called customer_orders.\n", - "customer_orders = set()" - ] - }, - { - "cell_type": "code", - "execution_count": 104, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PRODUCTS LIST: ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", - "From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter product nº 1: mug\n", - "Enter product nº 2: at\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Invalid input. You must enter a product from the list. Try again.\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter product nº 2: hat\n", - "Enter product nº 3: book\n" - ] - } - ], - "source": [ - "# 5 - Ask the user to input the name of three products that a customer wants to order\n", - "\n", - "print(\"PRODUCTS LIST: \", products)\n", - "print(\"From the PRODUCTS LIST, please enter the name of three products that a customer wants to order.\") \n", - "\n", - "while len(customer_orders) < 3:\n", - " order = input(f\"Enter product nº {len(customer_orders)+1}: \").strip().lower()\n", - " \n", - " if order in products:\n", - " if order in customer_orders:\n", - " print(f\"You've already entered '{order.upper()}'. Please enter a different product from the list.\")\n", - " else:\n", - " customer_orders.add(order)\n", - " else:\n", - " print(\"Invalid input. You must enter a product from the list. Try again.\")\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": 105, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'mug', 'book', 'hat'}\n" - ] - } - ], - "source": [ - "# 6 - Print the products in the `customer_orders` set.\n", - "\n", - "print(customer_orders)" - ] - }, - { - "cell_type": "code", - "execution_count": 106, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "60.0%\n" - ] - } - ], - "source": [ - "# 7- Calculate the following order statistics:\n", - " # 7.1 - Total Products Ordered: The total number of products in the `customer_orders` set.\n", - "total_products_ordered = len(customer_orders)\n", - " # 7.2 - Percentage of Products Ordered: The percentage of products ordered compared to the total available products.\n", - "percentage_of_products_ordered = (len(customer_orders)/len(products))*100\n", - "print(f\"{percentage_of_products_ordered}%\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 107, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Order Statistics:\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 60.0%\n" - ] - } - ], - "source": [ - "# 8 - Print the order statistics:\n", - "print(\"Order Statistics:\")\n", - "print(f\"Total Products Ordered: {total_products_ordered}\")\n", - "print(f\"Percentage of Products Ordered: {percentage_of_products_ordered}%\")\n" - ] - }, - { - "cell_type": "code", - "execution_count": 108, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'t-shirt': 9, 'mug': 9, 'hat': 9, 'book': 9, 'keychain': 9}\n" - ] - } - ], - "source": [ - "# 9 - Update the inventory by subtracting 1 from the quantity of each product. \n", - "for product in inventory:\n", - " inventory[product] -= 1" - ] - }, - { - "cell_type": "code", - "execution_count": 113, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "t-shirt: 9\n", - "mug: 9\n", - "hat: 9\n", - "book: 9\n", - "keychain: 9\n" - ] - } - ], - "source": [ - "# 10 - Print the updated inventory, displaying the quantity of each product on separate lines.\n", - "\n", - "for product, quantity in inventory.items():\n", - " print(f\"{product}: {quantity}\")" - ] - } - ], - "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 -}