From d995edee5e510241009344e1ff516f707897f1f8 Mon Sep 17 00:00:00 2001 From: mssamaniegocarriel-ctrl Date: Wed, 15 Apr 2026 17:54:44 +0200 Subject: [PATCH 1/3] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 140 ++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..269c968 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,147 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5b26388b", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "9854d464", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + " add_more = \"yes\"\n", + " while add_more == \"yes\":\n", + " product = input(\"Enter a product name: \")\n", + " customer_orders.add(product)\n", + " add_more = input(\"Do you want to add another product? (yes/no): \")\n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "21ef085f", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a965e021", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage = (total_ordered / len(products)) * 100\n", + " return total_ordered, percentage" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "82cd30da", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total Products Ordered: {total}\")\n", + " print(f\"Percentage of Products Ordered: {percentage:.2f}%\")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "bf4ae269", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "9f3461fe", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity of {product}: \"))\n", + " inventory[product] = quantity\n", + " return inventory\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " add_more = \"yes\"\n", + " while add_more == \"yes\":\n", + " product = input(\"Enter a product name: \")\n", + " customer_orders.add(product)\n", + " add_more = input(\"Do you want to add another product? (yes/no): \")\n", + " return customer_orders\n", + "\n", + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1\n", + " return inventory\n", + "\n", + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage = (total_ordered / len(products)) * 100\n", + " return total_ordered, percentage\n", + "\n", + "def print_order_statistics(order_statistics):\n", + " total, percentage = order_statistics\n", + " print(\"\\nOrder Statistics:\")\n", + " print(f\"Total Products Ordered: {total}\")\n", + " print(f\"Percentage of Products Ordered: {percentage:.2f}%\")\n", + "\n", + "def print_updated_inventory(inventory):\n", + " print(\"\\nUpdated Inventory:\")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")\n", + "\n", + "# --- Programa principal ---\n", + "products = [\"manzanas\", \"sandía\", \"banana\",\"fresas\",\"melón\"]\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": ".venv-1 (3.15.0)", "language": "python", "name": "python3" }, @@ -61,7 +197,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.15.0a7" } }, "nbformat": 4, From bf3ac588d9f3d07cbce7cc9cfffedd35d9967bcf Mon Sep 17 00:00:00 2001 From: mssamaniegocarriel-ctrl Date: Wed, 15 Apr 2026 17:54:48 +0200 Subject: [PATCH 2/3] Create python lab_functions.py --- python lab_functions.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 python lab_functions.py diff --git a/python lab_functions.py b/python lab_functions.py new file mode 100644 index 0000000..2e6536f --- /dev/null +++ b/python lab_functions.py @@ -0,0 +1 @@ +python lab_functions.py \ No newline at end of file From 6a7313656e152d27130931af7a1e25c9cc156529 Mon Sep 17 00:00:00 2001 From: mssamaniegocarriel-ctrl Date: Wed, 15 Apr 2026 17:54:52 +0200 Subject: [PATCH 3/3] Create lab_functions.py --- lab_functions.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lab_functions.py diff --git a/lab_functions.py b/lab_functions.py new file mode 100644 index 0000000..64d4775 --- /dev/null +++ b/lab_functions.py @@ -0,0 +1,48 @@ +def initialize_inventory(products): + products = ["manzanas", "sandía", "banana", "fresas", "melón"] + inventory = {} + for product in products: + quantity = int(input(f"Enter the quantity of {product}: ")) + inventory[product] = quantity + return inventory + +def get_customer_orders(): + customer_orders = set() + add_more = "yes" + while add_more == "yes": + product = input("Enter a product name: ") + customer_orders.add(product) + add_more = input("Do you want to add another product? (yes/no): ") + return customer_orders + +def update_inventory(customer_orders, inventory): + for product in customer_orders: + if product in inventory: + inventory[product] -= 1 + return inventory + +def calculate_order_statistics(customer_orders, products): + total_ordered = len(customer_orders) + percentage = (total_ordered / len(products)) * 100 + return total_ordered, percentage + +def print_order_statistics(order_statistics): + total, percentage = order_statistics + print("\nOrder Statistics:") + print(f"Total Products Ordered: {total}") + print(f"Percentage of Products Ordered: {percentage:.2f}%") + +def print_updated_inventory(inventory): + print("\nUpdated Inventory:") + for product, quantity in inventory.items(): + print(f"{product}: {quantity}") + +# --- Programa principal --- +products = ["manzanas", "sandía", "banana", "fresas", "melón"] + +inventory = initialize_inventory(products) +customer_orders = get_customer_orders() +inventory = update_inventory(customer_orders, inventory) +order_statistics = calculate_order_statistics(customer_orders, products) +print_order_statistics(order_statistics) +print_updated_inventory(inventory) \ No newline at end of file