From ac95a45cdf79c2b3551f4cf59a0e21b605556a82 Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Wed, 5 Nov 2025 14:25:38 +0100 Subject: [PATCH 1/6] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 72 +++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 5b3ce9e0..7dfec3d7 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -50,11 +50,79 @@ "\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": [ + "→ LAB SOLUTION STEP BY STEP: \n", + "By Marta Paulina Mamiaga Iyanga -\n", + "Ironhack Data Analytics Bootcamp" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# 1. We define the list \"products\" with \"t-shirt\", \"mug\", \"hat\" \"book\" and keychain as elements in it.hasattr\n", + "\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] \n", + "\n", + "# 2. We initialize an empty dictionary named \"inventory\" for the inventory of the products.\n", + "\n", + "inventory = {}\n", + "\n", + "# 3. We use a for loop to ask the user to input the quantity for each product in the \"products\" list.\n", + "\n", + "for products in products:\n", + " quantity = int(input(f\"Enter the quantity for {products}: \"))\n", + " inventory[products] = quantity\n", + "\n", + "# 4. We create an empty set for customer orders named \"customer_orders\".\n", + "\n", + "customer_orders = set()\n", + "\n", + "# 5. We prompt the user to enter three products\n", + "\n", + "for _ in range(3):\n", + " while True:\n", + " product_name = input(\"Enter a product name (e.g., t-shirt, mug, hat, book, keychain): \")\n", + " # Check if the input is in the products list\n", + " if product_name in products:\n", + " # Add the product to the set\n", + " customer_orders.add(product_name)\n", + " break\n", + " else:\n", + " print(\"Invalid product. Please try again.\")\n", + "\n", + "# We print the prodtucts in the \"customer_orders\" set.\n", + "\n", + "print(\"customer_orders:\" , customer_orders)\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] \n", + "\n", + "inventory = {}\n", + "for products in products:\n", + " quantity = int(input(f\"Enter the quantity for {products}: \"))\n", + " inventory[products] = quantity\n", + " print(\"inventory:\" , inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -68,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4, From 074e6c0f32a8aa77973a63a053c8d5e447de4599 Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:34:24 +0100 Subject: [PATCH 2/6] Finished Lab --- lab-python-data-structures.ipynb | 682 +++++++++++++++++++++++++++++-- 1 file changed, 650 insertions(+), 32 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 7dfec3d7..0be981d5 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -6,7 +6,8 @@ "tags": [] }, "source": [ - "# Lab | Data Structures " + "# Lab | Data Structures \n", + "-----" ] }, { @@ -55,9 +56,47 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "→ LAB SOLUTION STEP BY STEP: \n", - "By Marta Paulina Mamiaga Iyanga -\n", - "Ironhack Data Analytics Bootcamp" + "-----\n", + "# Managing Customer Orders\n", + "-----\n", + "By Paulina Mamiaga Iyanga / Ironhack Data Analytics Bootcamp Student\n", + "\n", + "--------" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "## STEPS TO FOLLOW:\n", + "------" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\". " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# define list products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(products)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "2. Create an empty dictionary called `inventory`." ] }, { @@ -66,42 +105,528 @@ "metadata": {}, "outputs": [], "source": [ - "# 1. We define the list \"products\" with \"t-shirt\", \"mug\", \"hat\" \"book\" and keychain as elements in it.hasattr\n", + "# create empty dict inventory\n", + "inventory = {}\n", + "print(inventory)\n", "\n", - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] \n", + "# Manual initalize dict inventory with products as keys and quantities as values\n", + "inventory = { \n", + " \"t-shirt\": 10,\n", + " \"mug\": 20,\n", + " \"hat\": 30,\n", + " \"book\": 40,\n", + " \"keychain\": 50\n", + "}\n", "\n", - "# 2. We initialize an empty dictionary named \"inventory\" for the inventory of the products.\n", + "print(inventory)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "3. Ask the user to input the quantity of each product available in the inventory. \n", + "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": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- t-shirt quantity updated to 10.\n", + "- mug quantity updated to 20.\n", + "- hat quantity updated to 30.\n", + "- book quantity updated to 40.\n", + "- keychain quantity updated to 50.\n", + "\n", + "Updated Inventory: {'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n" + ] + } + ], + "source": [ + "#3. user inputs the quantity of each product available in the inventory:\n", + "for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " print(f\"- {product} quantity updated to {quantity}.\")\n", + "print(\"\\nUpdated Inventory:\", inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# type of quantity is int if we use int(input(\"Enter quantity: \")) \n", + "type(quantity)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "4. Create an empty set called `customer_orders`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# initize empty set for customer orders\n", + "customer_orders = set()\n", + "print(customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\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." + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here are the available products : ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + " Empty Customer's orders: set()\n", + "- mug has been added to your order!\n", + "- hat has been added to your order!\n", + "- book has been added to your order!\n", + "\n", + "Updated Customer's orders: {'mug', 'hat', 'book'}\n" + ] + } + ], + "source": [ + "# 5. Ask the user to input 3 product names to add to a set called `customers_orders`.----------------\n", + "# define list products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(\"Here are the available products :\", products)\n", "\n", - "inventory = {}\n", + "# Empty customer orders set for testing\n", + "customer_orders = set()\n", + "print(\"\\n Empty Customer's orders:\", customer_orders)\n", + "\n", + "# INPUT 3 PRODUCTS using loop\n", + "for i in range(3):\n", "\n", - "# 3. We use a for loop to ask the user to input the quantity for each product in the \"products\" list.\n", + " product = input(\"Enter product name: \").lower() # convert input to lowercase\n", + " if product in products:\n", + " print(f\"- {product} has been added to your order!\")\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Please input product from the list: \", products)\n", + " continue # skip to next iteration if product not in list\n", + " \n", "\n", - "for products in products:\n", - " quantity = int(input(f\"Enter the quantity for {products}: \"))\n", - " inventory[products] = quantity\n", + "# updated customer orders set with products for testing\n", + "print(\"\\nUpdated Customer's orders:\", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Here are the available products : ['t-shirt', 'mug', 'hat', 'book', 'keychain']\n", + "\n", + " Empty Customer's orders: set() \n", + "\n", + "- mug has been added to your order!\n", + "- book has been added to your order!\n", + "- hat has been added to your order!\n", + "Thank you for your purchase!\n", + "\n", + "Updated Customer's orders: {'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "# 5. using while instead of for loop---------------------------------------------------------------------------------\n", "\n", - "# 4. We create an empty set for customer orders named \"customer_orders\".\n", + "# define list products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "print(\"Here are the available products :\", products)\n", "\n", + "# Empty customer orders set for testing\n", "customer_orders = set()\n", + "print(\"\\n Empty Customer's orders:\", customer_orders, \"\\n\")\n", "\n", - "# 5. We prompt the user to enter three products\n", + "# must initialize product variable before while loop\n", + "product = \"\"\n", + "# INPUT 3 PRODUCTS using loop\n", + "while product !=\"buy\": # keep asking for product input until we write buy\n", "\n", - "for _ in range(3):\n", - " while True:\n", - " product_name = input(\"Enter a product name (e.g., t-shirt, mug, hat, book, keychain): \")\n", - " # Check if the input is in the products list\n", - " if product_name in products:\n", - " # Add the product to the set\n", - " customer_orders.add(product_name)\n", - " break\n", - " else:\n", - " print(\"Invalid product. Please try again.\")\n", + " product = input(\"Enter product name: \").lower() # convert input to lowercase\n", + " if product in products:\n", + " print(f\"- {product} has been added to your order!\")\n", + " customer_orders.add(product)\n", + " \n", + " elif product == \"buy\":\n", + " print(\"Thank you for your purchase!\")\n", + " break\n", "\n", - "# We print the prodtucts in the \"customer_orders\" set.\n", + " else:\n", + " print(\"Please input product from the list: \", products)\n", + " continue # skip to next iteration if product not in list\n", + " \n", "\n", - "print(\"customer_orders:\" , customer_orders)\n", + "# updated customer orders set with products for testing\n", + "print(\"\\nUpdated Customer's orders:\", customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "6. Print the products in the `customer_orders` set." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'hat', 'mug', 'book'}\n", + "\n", + "Updated Customer's orders: {'hat', 'mug', 'book'}\n" + ] + } + ], + "source": [ + "# 6. printing the Updated Customer's orders: ----------------------------------------------------------------\n", + "print(\"\\nUpdated Customer's orders:\", customer_orders)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\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`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00%\n" + ] + } + ], + "source": [ + "# 7. Calculate the following order statistics: ------------------------------------------------------------\n", + "# 7.1. Total products ordered\n", + "total_products_ordered = len(customer_orders)\n", + "print(f\"\\nTotal Products Ordered: {total_products_ordered}\")\n", + "\n", + "# 7.2. Percentage products ordered from total products ordered\n", + "percentage = total_products_ordered / len(products) * 100\n", "\n", - "\n" + "print(f\"Percentage of Products Ordered: {percentage:.2f}%\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\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": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Order Statistics:\n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.00% \n" + ] + } + ], + "source": [ + "# Print the order statistics using the following format:\n", + "\n", + "# Order Statistics:\n", + "print(\"\\nOrder Statistics:\")\n", + "\n", + "# Total Products Ordered: \n", + "print(f\"Total Products Ordered: {total_products_ordered}\")\n", + "\n", + "# Percentage of Products Ordered: % \n", + "print(f\"Percentage of Products Ordered: {percentage:.2f}% \")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "9. Update the inventory by subtracting 1 from the quantity of each product. Modify the `inventory` dictionary accordingly." + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- mug inventory decreased by 1. New quantity: 19\n", + "- hat inventory decreased by 1. New quantity: 29\n", + "- book inventory decreased by 1. New quantity: 39\n" + ] + } + ], + "source": [ + "# 9. Update the inventory dict by substracting 1 from products in customer_orders set ---------------------------------------------\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + " print(f\"- {product} inventory decreased by 1. New quantity: {inventory[product]}\")\n", + " else:\n", + " print(f\"- {product} is out of stock!\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "10. Print the updated inventory, displaying the quantity of each product on separate lines." + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory after Customer's orders: {'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}\n", + "- t-shirt: 10 units left\n", + "- mug: 19 units left\n", + "- hat: 29 units left\n", + "- book: 39 units left\n", + "- keychain: 50 units left\n" + ] + } + ], + "source": [ + "# Print the updated inventory\n", + "print(\"\\nUpdated Inventory after Customer's orders:\", inventory)\n", + "for product in products:\n", + " print(f\"- {product}: {inventory[product]} units left\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Updated Inventory after Customer's orders:\n", + "- t-shirt: 10 units left\n", + "- mug: 19 units left\n", + "- hat: 29 units left\n", + "- book: 39 units left\n", + "- keychain: 50 units left\n" + ] + } + ], + "source": [ + "# Another way to print the updated inventory\n", + "print(\"\\nUpdated Inventory after Customer's orders:\")\n", + "for product, quantity in inventory.items():\n", + " print(f\"- {product}: {quantity} units left\")\n", + "\n", + "# for key, value in dictionary.items():\n", + "# print(f\"{key}: {value}\")\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "-----\n", + "### HOW TO ?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "How to copy? CTRL + C\n", + "\n", + "How to cut? CTRL + X \n", + "\n", + "How to paste? CTRL + V" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Another way to print the updated inventory dict using .items()\n", + "# for key, value in dictionary.items():\n", + "# print(f\"{key}: {value}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Different Ways to write mathematical operations----------------------------- \n", + "# Subtraction\n", + "inventory[product] -= 1\n", + "inventory[product] = inventory[product] - 1\n", + "\n", + "# Addition\n", + "inventory[product] += 1\n", + "inventory[product] = inventory[product] + 1\n", + "\n", + "# Division\n", + "inventory[product] /= 1\n", + "inventory[product] = inventory[product] / 1\n", + "\n", + "# Multiplication\n", + "inventory[product] *= 1\n", + "inventory[product] = inventory[product] * 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty set called \"customers_orders\n", + "customers_orders = set()\n", + "print(customers_orders)\n", + "\n", + "#-----------------------------------------------------------------------------------------\n", + "# How to define EMPTY different data structures in Python :\n", + "# set_name = set()\n", + "# list_name = []\n", + "# dict_name = {}\n", + "# tuple_name = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Create an empty set called \"customers_orders\n", + "customer_orders = set()\n", + "print(customer_orders)\n", + "\n", + "#-----------------------------------------------------------------------------------------\n", + "# How to define EMPTY different data structures in Python :\n", + "# set_name = set()\n", + "# list_name = []\n", + "# dict_name = {}\n", + "# tuple_name = {}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# The different way to add between set and list---------------\n", + "\n", + "# How to add to a set\n", + "customer_orders.add(product)\n", + "\n", + "# How to add to a list\n", + "customer_orders.append(product)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# customer orders empty set\n", + "customer_orders = set()\n", + "print(\"\\nCustomer's orders:\", customer_orders)\n", + "\n", + "# INPUT 3 PRODUCTS using loop\n", + "print(range(3))\n", + "for i in range(3):\n", + " product = input(\"Enter product name: \")\n", + " print(f\"- {product}\")\n", + " customer_orders.add(product)\n", + "\n", + "# customer orders set with products\n", + "print(\"\\nCustomer's orders:\", customer_orders)\n" ] }, { @@ -110,14 +635,107 @@ "metadata": {}, "outputs": [], "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] \n", + "# input 1 product\n", + "product = input(\"Enter product name: \")\n", + "\n", + "# INPUT 3 PRODUCTS using loop\n", + "print(range(3))\n", + "for i in range(3):\n", + " print(\"Line number :\", i)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# ==========================\n", + "# Managing Customer Orders\n", + "# ==========================\n", + "# By Paulina Mamiaga Iyanga / Ironhack Data Analytics Bootcamp Student\n", + "\n", + "\n", + "# STEPS TO FOLLOW:\n", + "\n", + "# 1. We define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", + "#1. define List : products\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "# 2. We create an empty dictionary called `inventory`.\n", "\n", "inventory = {}\n", - "for products in products:\n", - " quantity = int(input(f\"Enter the quantity for {products}: \"))\n", - " inventory[products] = quantity\n", - " print(\"inventory:\" , inventory)" + "\n", + "# 3. We prompt an input asking the user to put the quantity of each product available in the inventory. \n", + "# Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", + "\n", + "for product in products:\n", + " while True:\n", + " qty_str = input(f\"Enter the quantity for {product}: \").strip()\n", + " if qty_str.isdigit(): # verify that the input is a whole number\n", + " quantity = int(qty_str)\n", + " inventory[product] = quantity\n", + " break\n", + " else:\n", + " print(\"Please enter a valid whole number (0, 1, 2, ...)\")\n", + "\n", + "# 4. We create an empty set called \"customer_orders\".\n", + "\n", + "customer_orders = set()\n", + "\n", + "# 5. We prompt another input asking the user to put 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", + "for _ in range(3):\n", + " order = input(\"Enter the name of a product to order: \")\n", + " if order in products:\n", + " customer_orders.add(order)\n", + " else:\n", + " print(\"Product not available.\")\n", + "\n", + "# 6. Print the products in the `customer_orders` set.\n", + " \n", + "print(\"\\nCustomer_orders:\" , customer_orders)\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", + "# Store these statistics in a tuple called `order_status`.\n", + "\n", + "total_products_ordered = len(customer_orders)\n", + "percentage_products_ordered = (total_products_ordered / len(products)) * 100\n", + " \n", + "order_status = (total_products_ordered, percentage_products_ordered)\n", + "\n", + "# 8. We prompt the order statistics for it to be printed, using the following format:\n", + "# Order Statistics:\n", + "# -Total Products Ordered: \n", + "# - Percentage of Products Ordered: % \n", + "\n", + "print(\"\\nOrder Statistics:\")\n", + "print(f\"- Total Products Ordered: {order_status[0]}\")\n", + "print(f\"- Percentage of products Ordered: {order_status[1]:.2f}%\")\n", + "\n", + "\n", + "# 9. We prompt the inventory update by subtracting 1 from the quantity of each product and the `inventory` dictionary modification accordingly.\n", + "\n", + "for product in customer_orders:\n", + " if inventory[product] > 0:\n", + " inventory[product] -= 1\n", + "\n", + "# 10. We prompt the printing of the updated inventory, displaying the quantity of each product on separate lines.\n", + " \n", + "print(\"\\nUpdated Inventory:\")\n", + "for products, quantity in inventory.items():\n", + " print(f\"{products}: {quantity}\")\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From 27601475a392ffa31fa16a3f91ef8e1f6a089135 Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:39:18 +0100 Subject: [PATCH 3/6] 22:38 / 05.11.25 / Update --- lab-python-data-structures.ipynb | 86 -------------------------------- 1 file changed, 86 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 0be981d5..b1a19e4f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -644,92 +644,6 @@ " print(\"Line number :\", i)\n" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# ==========================\n", - "# Managing Customer Orders\n", - "# ==========================\n", - "# By Paulina Mamiaga Iyanga / Ironhack Data Analytics Bootcamp Student\n", - "\n", - "\n", - "# STEPS TO FOLLOW:\n", - "\n", - "# 1. We define a list called `products` that contains the following items: \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\".\n", - "#1. define List : products\n", - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "\n", - "# 2. We create an empty dictionary called `inventory`.\n", - "\n", - "inventory = {}\n", - "\n", - "# 3. We prompt an input asking the user to put the quantity of each product available in the inventory. \n", - "# Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n", - "\n", - "for product in products:\n", - " while True:\n", - " qty_str = input(f\"Enter the quantity for {product}: \").strip()\n", - " if qty_str.isdigit(): # verify that the input is a whole number\n", - " quantity = int(qty_str)\n", - " inventory[product] = quantity\n", - " break\n", - " else:\n", - " print(\"Please enter a valid whole number (0, 1, 2, ...)\")\n", - "\n", - "# 4. We create an empty set called \"customer_orders\".\n", - "\n", - "customer_orders = set()\n", - "\n", - "# 5. We prompt another input asking the user to put 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", - "for _ in range(3):\n", - " order = input(\"Enter the name of a product to order: \")\n", - " if order in products:\n", - " customer_orders.add(order)\n", - " else:\n", - " print(\"Product not available.\")\n", - "\n", - "# 6. Print the products in the `customer_orders` set.\n", - " \n", - "print(\"\\nCustomer_orders:\" , customer_orders)\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", - "# Store these statistics in a tuple called `order_status`.\n", - "\n", - "total_products_ordered = len(customer_orders)\n", - "percentage_products_ordered = (total_products_ordered / len(products)) * 100\n", - " \n", - "order_status = (total_products_ordered, percentage_products_ordered)\n", - "\n", - "# 8. We prompt the order statistics for it to be printed, using the following format:\n", - "# Order Statistics:\n", - "# -Total Products Ordered: \n", - "# - Percentage of Products Ordered: % \n", - "\n", - "print(\"\\nOrder Statistics:\")\n", - "print(f\"- Total Products Ordered: {order_status[0]}\")\n", - "print(f\"- Percentage of products Ordered: {order_status[1]:.2f}%\")\n", - "\n", - "\n", - "# 9. We prompt the inventory update by subtracting 1 from the quantity of each product and the `inventory` dictionary modification accordingly.\n", - "\n", - "for product in customer_orders:\n", - " if inventory[product] > 0:\n", - " inventory[product] -= 1\n", - "\n", - "# 10. We prompt the printing of the updated inventory, displaying the quantity of each product on separate lines.\n", - " \n", - "print(\"\\nUpdated Inventory:\")\n", - "for products, quantity in inventory.items():\n", - " print(f\"{products}: {quantity}\")\n" - ] - }, { "cell_type": "code", "execution_count": null, From d94f666b6b8b5e081a3386d936a6951249f521ca Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Wed, 5 Nov 2025 22:42:37 +0100 Subject: [PATCH 4/6] 05.11.25 / 22:41 / Update --- lab-python-data-structures.ipynb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index b1a19e4f..042112aa 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -631,9 +631,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "range(0, 3)\n", + "Line number : 0\n", + "Line number : 1\n", + "Line number : 2\n" + ] + } + ], "source": [ "# input 1 product\n", "product = input(\"Enter product name: \")\n", @@ -641,15 +652,9 @@ "# INPUT 3 PRODUCTS using loop\n", "print(range(3))\n", "for i in range(3):\n", - " print(\"Line number :\", i)\n" + " print(\"Line number :\", i)\n", + "\n" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From 11d1aa2e6418582e3eba1a503648a9e16cac5188 Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Thu, 6 Nov 2025 00:00:48 +0100 Subject: [PATCH 5/6] 06.11.2025 /Updated --- lab-python-data-structures.ipynb | 130 +++++++++++++++++++------------ 1 file changed, 79 insertions(+), 51 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 042112aa..30c5a016 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -82,9 +82,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['t-shirt', 'mug', 'hat', 'book', 'keychain']\n" + ] + } + ], "source": [ "# define list products\n", "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", @@ -101,9 +109,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n", + "{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n" + ] + } + ], "source": [ "# create empty dict inventory\n", "inventory = {}\n", @@ -132,25 +149,27 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "- t-shirt quantity updated to 10.\n", - "- mug quantity updated to 20.\n", - "- hat quantity updated to 30.\n", - "- book quantity updated to 40.\n", - "- keychain quantity updated to 50.\n", + "- t-shirt quantity updated to 56.\n", + "- mug quantity updated to 67.\n", + "- hat quantity updated to 87.\n", + "- book quantity updated to 90.\n", + "- keychain quantity updated to 90.\n", "\n", - "Updated Inventory: {'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n" + "Updated Inventory: {'t-shirt': 56, 'mug': 67, 'hat': 87, 'book': 90, 'keychain': 90}\n" ] } ], "source": [ "#3. user inputs the quantity of each product available in the inventory:\n", + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", "for product in products:\n", " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", " inventory[product] = quantity\n", @@ -158,16 +177,6 @@ "print(\"\\nUpdated Inventory:\", inventory)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# type of quantity is int if we use int(input(\"Enter quantity: \")) \n", - "type(quantity)" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -178,9 +187,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n" + ] + } + ], "source": [ "# initize empty set for customer orders\n", "customer_orders = set()\n", @@ -197,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -209,9 +226,9 @@ " Empty Customer's orders: set()\n", "- mug has been added to your order!\n", "- hat has been added to your order!\n", - "- book has been added to your order!\n", + "- t-shirt has been added to your order!\n", "\n", - "Updated Customer's orders: {'mug', 'hat', 'book'}\n" + "Updated Customer's orders: {'hat', 'mug', 't-shirt'}\n" ] } ], @@ -243,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -255,11 +272,13 @@ " Empty Customer's orders: set() \n", "\n", "- mug has been added to your order!\n", - "- book has been added to your order!\n", "- hat has been added to your order!\n", + "- t-shirt has been added to your order!\n", + "- book has been added to your order!\n", + "- keychain has been added to your order!\n", "Thank you for your purchase!\n", "\n", - "Updated Customer's orders: {'hat', 'mug', 'book'}\n" + "Updated Customer's orders: {'book', 't-shirt', 'hat', 'mug', 'keychain'}\n" ] } ], @@ -307,16 +326,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "{'hat', 'mug', 'book'}\n", "\n", - "Updated Customer's orders: {'hat', 'mug', 'book'}\n" + "Updated Customer's orders: {'book', 't-shirt', 'hat', 'mug', 'keychain'}\n" ] } ], @@ -339,7 +357,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -347,21 +365,29 @@ "output_type": "stream", "text": [ "\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 60.00%\n" + "Total Products Ordered: 5\n", + "Percentage of Products Ordered: 100.00%\n", + "\n", + "Order Status (Total Products Ordered, Percentage): (5, 100.0)\n" ] } ], "source": [ "# 7. Calculate the following order statistics: ------------------------------------------------------------\n", "# 7.1. Total products ordered\n", + "\n", "total_products_ordered = len(customer_orders)\n", "print(f\"\\nTotal Products Ordered: {total_products_ordered}\")\n", "\n", "# 7.2. Percentage products ordered from total products ordered\n", "percentage = total_products_ordered / len(products) * 100\n", "\n", - "print(f\"Percentage of Products Ordered: {percentage:.2f}%\")" + "print(f\"Percentage of Products Ordered: {percentage:.2f}%\")\n", + "\n", + "# Store these statistics in a tuple called `order_status`.\n", + "\n", + "order_status = (total_products_ordered, percentage)\n", + "print(\"\\nOrder Status (Total Products Ordered, Percentage):\", order_status)" ] }, { @@ -379,7 +405,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -388,8 +414,8 @@ "text": [ "\n", "Order Statistics:\n", - "Total Products Ordered: 3\n", - "Percentage of Products Ordered: 60.00% \n" + "Total Products Ordered: 5\n", + "Percentage of Products Ordered: 100.00% \n" ] } ], @@ -416,16 +442,18 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "- mug inventory decreased by 1. New quantity: 19\n", - "- hat inventory decreased by 1. New quantity: 29\n", - "- book inventory decreased by 1. New quantity: 39\n" + "- book inventory decreased by 1. New quantity: 89\n", + "- t-shirt inventory decreased by 1. New quantity: 55\n", + "- hat inventory decreased by 1. New quantity: 86\n", + "- mug inventory decreased by 1. New quantity: 66\n", + "- keychain inventory decreased by 1. New quantity: 89\n" ] } ], @@ -449,7 +477,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -457,12 +485,12 @@ "output_type": "stream", "text": [ "\n", - "Updated Inventory after Customer's orders: {'t-shirt': 10, 'mug': 19, 'hat': 29, 'book': 39, 'keychain': 50}\n", - "- t-shirt: 10 units left\n", - "- mug: 19 units left\n", - "- hat: 29 units left\n", - "- book: 39 units left\n", - "- keychain: 50 units left\n" + "Updated Inventory after Customer's orders: {'t-shirt': 55, 'mug': 66, 'hat': 86, 'book': 89, 'keychain': 89}\n", + "- t-shirt: 55 units left\n", + "- mug: 66 units left\n", + "- hat: 86 units left\n", + "- book: 89 units left\n", + "- keychain: 89 units left\n" ] } ], @@ -631,7 +659,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": null, "metadata": {}, "outputs": [ { From 20e98374fecd4beedb11ba0495000b8cecef599c Mon Sep 17 00:00:00 2001 From: PaulinaMamiaga <228375023+PaulinaMamiaga@users.noreply.github.com> Date: Thu, 6 Nov 2025 00:14:06 +0100 Subject: [PATCH 6/6] 06.11.2025 /Update --- lab-python-data-structures.ipynb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 30c5a016..33fa331e 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -504,7 +504,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -513,11 +513,11 @@ "text": [ "\n", "Updated Inventory after Customer's orders:\n", - "- t-shirt: 10 units left\n", - "- mug: 19 units left\n", - "- hat: 29 units left\n", - "- book: 39 units left\n", - "- keychain: 50 units left\n" + "- t-shirt: 55 units left\n", + "- mug: 66 units left\n", + "- hat: 86 units left\n", + "- book: 89 units left\n", + "- keychain: 89 units left\n" ] } ], @@ -528,7 +528,8 @@ " print(f\"- {product}: {quantity} units left\")\n", "\n", "# for key, value in dictionary.items():\n", - "# print(f\"{key}: {value}\")\n" + "# print(f\"{key}: {value}\")\n", + "\n" ] }, {