From 2e375ed589b430b0394183dc8be65de77b70f23d Mon Sep 17 00:00:00 2001 From: fisicangel Date: Fri, 31 Jul 2026 14:53:59 +0200 Subject: [PATCH 1/5] Lab Angelica Functions --- lab_python_functions.ipynb | 119 +++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 lab_python_functions.ipynb diff --git a/lab_python_functions.ipynb b/lab_python_functions.ipynb new file mode 100644 index 0000000..ea82109 --- /dev/null +++ b/lab_python_functions.ipynb @@ -0,0 +1,119 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": { + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e" + }, + "source": [ + "# Lab | Functions" + ] + }, + { + "cell_type": "markdown", + "id": "0c581062-8967-4d93-b06e-62833222f930", + "metadata": { + "tags": [], + "id": "0c581062-8967-4d93-b06e-62833222f930" + }, + "source": [ + "## Exercise: Managing Customer Orders with Functions\n", + "\n", + "In the previous exercise, you improved the code for managing customer orders by using loops and flow control. Now, let's take it a step further and refactor the code by introducing functions.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a function named `initialize_inventory` that takes `products` as a parameter. Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", + "\n", + "2. Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement the code for prompting the user to enter the product names using a loop. The function should return the `customer_orders` set.\n", + "\n", + "3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "\n", + "4. Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` as parameters. Inside the function, implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered). The function should return these values.\n", + "\n", + "5. Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the function, implement the code for printing the order statistics.\n", + "\n", + "6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, implement the code for printing the updated inventory.\n", + "\n", + "7. Call the functions in the appropriate sequence to execute the program and manage customer orders.\n", + "\n", + "Hints for functions:\n", + "\n", + "- Consider the input parameters required for each function and their return values.\n", + "- Utilize function parameters and return values to transfer data between functions.\n", + "- Test your functions individually to ensure they work correctly.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " qty = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = qty\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "for i in products:\n", + " order = input(f\"Enter product to order: \").strip()\n", + " #if order in products:\n", + " #customer_orders.add(order)\n", + " #else:\n", + " #print(f\"{order} is not a valid product.\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "_B3mj75_0hrN", + "outputId": "1e09cfc2-96eb-42d5-a467-c315718ac585" + }, + "id": "_B3mj75_0hrN", + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter product to order: har\n", + "Enter product to order: hat\n", + "Enter product to order: book\n", + "Enter product to order: keychain\n", + "Enter product to order: mug\n" + ] + } + ] + } + ], + "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.9.13" + }, + "colab": { + "provenance": [] + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From b245ee9aafcc80947df1f72e8a8a76b28df93fc5 Mon Sep 17 00:00:00 2001 From: fisicangel Date: Fri, 31 Jul 2026 15:54:58 +0200 Subject: [PATCH 2/5] Delete lab_python_functions.ipynb --- lab_python_functions.ipynb | 119 ------------------------------------- 1 file changed, 119 deletions(-) delete mode 100644 lab_python_functions.ipynb diff --git a/lab_python_functions.ipynb b/lab_python_functions.ipynb deleted file mode 100644 index ea82109..0000000 --- a/lab_python_functions.ipynb +++ /dev/null @@ -1,119 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", - "metadata": { - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e" - }, - "source": [ - "# Lab | Functions" - ] - }, - { - "cell_type": "markdown", - "id": "0c581062-8967-4d93-b06e-62833222f930", - "metadata": { - "tags": [], - "id": "0c581062-8967-4d93-b06e-62833222f930" - }, - "source": [ - "## Exercise: Managing Customer Orders with Functions\n", - "\n", - "In the previous exercise, you improved the code for managing customer orders by using loops and flow control. Now, let's take it a step further and refactor the code by introducing functions.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a function named `initialize_inventory` that takes `products` as a parameter. Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", - "\n", - "2. Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement the code for prompting the user to enter the product names using a loop. The function should return the `customer_orders` set.\n", - "\n", - "3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", - "\n", - "4. Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` as parameters. Inside the function, implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered). The function should return these values.\n", - "\n", - "5. Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the function, implement the code for printing the order statistics.\n", - "\n", - "6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, implement the code for printing the updated inventory.\n", - "\n", - "7. Call the functions in the appropriate sequence to execute the program and manage customer orders.\n", - "\n", - "Hints for functions:\n", - "\n", - "- Consider the input parameters required for each function and their return values.\n", - "- Utilize function parameters and return values to transfer data between functions.\n", - "- Test your functions individually to ensure they work correctly.\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "source": [ - "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", - "def initialize_inventory(products):\n", - " inventory = {}\n", - "\n", - " for product in products:\n", - " qty = int(input(f\"Enter quantity for {product}: \"))\n", - " inventory[product] = qty\n", - " return inventory\n", - "\n", - "def get_customer_orders():\n", - " customer_orders = set()\n", - "for i in products:\n", - " order = input(f\"Enter product to order: \").strip()\n", - " #if order in products:\n", - " #customer_orders.add(order)\n", - " #else:\n", - " #print(f\"{order} is not a valid product.\")" - ], - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "_B3mj75_0hrN", - "outputId": "1e09cfc2-96eb-42d5-a467-c315718ac585" - }, - "id": "_B3mj75_0hrN", - "execution_count": null, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter product to order: har\n", - "Enter product to order: hat\n", - "Enter product to order: book\n", - "Enter product to order: keychain\n", - "Enter product to order: mug\n" - ] - } - ] - } - ], - "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.9.13" - }, - "colab": { - "provenance": [] - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} \ No newline at end of file From fee4387aed9850790b18b1eac64dfa3aab404082 Mon Sep 17 00:00:00 2001 From: fisicangel Date: Fri, 31 Jul 2026 15:55:45 +0200 Subject: [PATCH 3/5] Creado con Colab --- lab-python-functions.ipynb | 195 ++++++++++++++++++++++++------------- 1 file changed, 128 insertions(+), 67 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..28ca38f 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -1,69 +1,130 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", - "metadata": {}, - "source": [ - "# Lab | Functions" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "markdown", + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "metadata": { + "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e" + }, + "source": [ + "# Lab | Functions" + ] + }, + { + "cell_type": "markdown", + "id": "0c581062-8967-4d93-b06e-62833222f930", + "metadata": { + "tags": [], + "id": "0c581062-8967-4d93-b06e-62833222f930" + }, + "source": [ + "## Exercise: Managing Customer Orders with Functions\n", + "\n", + "In the previous exercise, you improved the code for managing customer orders by using loops and flow control. Now, let's take it a step further and refactor the code by introducing functions.\n", + "\n", + "Follow the steps below to complete the exercise:\n", + "\n", + "1. Define a function named `initialize_inventory` that takes `products` as a parameter. Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", + "\n", + "2. Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement the code for prompting the user to enter the product names using a loop. The function should return the `customer_orders` set.\n", + "\n", + "3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", + "\n", + "4. Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` as parameters. Inside the function, implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered). The function should return these values.\n", + "\n", + "5. Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the function, implement the code for printing the order statistics.\n", + "\n", + "6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, implement the code for printing the updated inventory.\n", + "\n", + "7. Call the functions in the appropriate sequence to execute the program and manage customer orders.\n", + "\n", + "Hints for functions:\n", + "\n", + "- Consider the input parameters required for each function and their return values.\n", + "- Utilize function parameters and return values to transfer data between functions.\n", + "- Test your functions individually to ensure they work correctly.\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " qty = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = qty\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + "for i in products:\n", + " order = input(f\"Enter product to order: \").strip()\n", + " #if order in products:\n", + " #customer_orders.add(order)\n", + " #else:\n", + " #print(f\"{order} is not a valid product.\")" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "_B3mj75_0hrN", + "outputId": "1e09cfc2-96eb-42d5-a467-c315718ac585" + }, + "id": "_B3mj75_0hrN", + "execution_count": null, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter product to order: har\n", + "Enter product to order: hat\n", + "Enter product to order: book\n", + "Enter product to order: keychain\n", + "Enter product to order: mug\n" + ] + } + ] + } + ], + "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.9.13" + }, + "colab": { + "provenance": [], + "include_colab_link": true + } }, - { - "cell_type": "markdown", - "id": "0c581062-8967-4d93-b06e-62833222f930", - "metadata": { - "tags": [] - }, - "source": [ - "## Exercise: Managing Customer Orders with Functions\n", - "\n", - "In the previous exercise, you improved the code for managing customer orders by using loops and flow control. Now, let's take it a step further and refactor the code by introducing functions.\n", - "\n", - "Follow the steps below to complete the exercise:\n", - "\n", - "1. Define a function named `initialize_inventory` that takes `products` as a parameter. Inside the function, implement the code for initializing the inventory dictionary using a loop and user input.\n", - "\n", - "2. Define a function named `get_customer_orders` that takes no parameters. Inside the function, implement the code for prompting the user to enter the product names using a loop. The function should return the `customer_orders` set.\n", - "\n", - "3. Define a function named `update_inventory` that takes `customer_orders` and `inventory` as parameters. Inside the function, implement the code for updating the inventory dictionary based on the customer orders.\n", - "\n", - "4. Define a function named `calculate_order_statistics` that takes `customer_orders` and `products` as parameters. Inside the function, implement the code for calculating the order statistics (total products ordered, and percentage of unique products ordered). The function should return these values.\n", - "\n", - "5. Define a function named `print_order_statistics` that takes `order_statistics` as a parameter. Inside the function, implement the code for printing the order statistics.\n", - "\n", - "6. Define a function named `print_updated_inventory` that takes `inventory` as a parameter. Inside the function, implement the code for printing the updated inventory.\n", - "\n", - "7. Call the functions in the appropriate sequence to execute the program and manage customer orders.\n", - "\n", - "Hints for functions:\n", - "\n", - "- Consider the input parameters required for each function and their return values.\n", - "- Utilize function parameters and return values to transfer data between functions.\n", - "- Test your functions individually to ensure they work correctly.\n", - "\n", - "\n" - ] - } - ], - "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.9.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From 23839e865300adb6eb163cf111171e57aab6d201 Mon Sep 17 00:00:00 2001 From: fisicangel Date: Fri, 31 Jul 2026 16:01:58 +0200 Subject: [PATCH 4/5] Lab Ange --- lab-python-functions.ipynb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 28ca38f..ea82109 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -1,15 +1,5 @@ { "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, { "cell_type": "markdown", "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", @@ -121,8 +111,7 @@ "version": "3.9.13" }, "colab": { - "provenance": [], - "include_colab_link": true + "provenance": [] } }, "nbformat": 4, From 9feb5bffcc9c56dcc783de6f33568df41086cf3a Mon Sep 17 00:00:00 2001 From: fisicangel Date: Fri, 31 Jul 2026 19:03:44 +0200 Subject: [PATCH 5/5] Reviewed --- lab-python-functions.ipynb | 107 +++++++++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index ea82109..fc88c13 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -51,42 +51,107 @@ "cell_type": "code", "source": [ "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "inventory = {}\n", + "\n", "def initialize_inventory(products):\n", - " inventory = {}\n", + " inventory = {}\n", + "\n", + " for product in products:\n", + " quantity = int(input(f\"Enter quantity for {product}: \"))\n", + " inventory[product] = quantity\n", "\n", - " for product in products:\n", - " qty = int(input(f\"Enter quantity for {product}: \"))\n", - " inventory[product] = qty\n", - " return inventory\n", + " return inventory\n", "\n", "def get_customer_orders():\n", - " customer_orders = set()\n", - "for i in products:\n", - " order = input(f\"Enter product to order: \").strip()\n", - " #if order in products:\n", - " #customer_orders.add(order)\n", - " #else:\n", - " #print(f\"{order} is not a valid product.\")" + " customer_orders = set()\n", + "\n", + " print(\"\\nEnter 3 products the customer wants:\")\n", + "\n", + " for i in range(3):\n", + " product = input(f\"Product {i + 1}: \")\n", + " customer_orders.add(product)\n", + "\n", + " return customer_orders\n", + "\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " else:\n", + " #customer_orders.remove(product)\n", + " #revomed_product += 1\n", + " print(f\"{product} is not in the inventory.\")\n", + "\n", + "# Function to calculate order statistics\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_products_ordered = len(customer_orders)\n", + " percentage_ordered = (total_products_ordered / len(products)) * 100\n", + "\n", + " return total_products_ordered, percentage_ordered\n", + "\n", + "\n", + "# Function to print the order statistics\n", + "def print_order_statistics(order_statistics):\n", + " total_products_ordered, percentage_ordered = order_statistics\n", + "\n", + " print(\"Order Statistics\")\n", + " print(f\"Total products ordered: {total_products_ordered}\")\n", + " print(f\"Percentage of unique products ordered: {percentage_ordered:.2f}%\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + "\n", + " print(\"Updated Inventory\")\n", + "\n", + " for product, quantity in inventory.items():\n", + " print(product, quantity)\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "update_inventory(customer_orders, inventory)\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print_order_statistics(order_statistics)\n", + "\n", + "print_updated_inventory(inventory)" ], "metadata": { + "id": "_B3mj75_0hrN", "colab": { "base_uri": "https://localhost:8080/" }, - "id": "_B3mj75_0hrN", - "outputId": "1e09cfc2-96eb-42d5-a467-c315718ac585" + "outputId": "b7567817-d53a-4a62-e88c-8b54d0e144b2" }, "id": "_B3mj75_0hrN", - "execution_count": null, + "execution_count": 21, "outputs": [ { - "name": "stdout", "output_type": "stream", + "name": "stdout", "text": [ - "Enter product to order: har\n", - "Enter product to order: hat\n", - "Enter product to order: book\n", - "Enter product to order: keychain\n", - "Enter product to order: mug\n" + "Enter quantity for t-shirt: 2\n", + "Enter quantity for mug: 3\n", + "Enter quantity for hat: 4\n", + "Enter quantity for book: 5\n", + "Enter quantity for keychain: 6\n", + "\n", + "Enter 3 products the customer wants:\n", + "Product 1: muh\n", + "Product 2: hat\n", + "Product 3: book\n", + "muh is not in the inventory.\n", + "Order Statistics\n", + "Total products ordered: 3\n", + "Percentage of unique products ordered: 60.00%\n", + "Updated Inventory\n", + "t-shirt 2\n", + "mug 3\n", + "hat 3\n", + "book 4\n", + "keychain 6\n" ] } ]