From c754d3e5febade8c0ab8f52e28d74bde6adb4aa7 Mon Sep 17 00:00:00 2001 From: carmenlnr Date: Wed, 15 Apr 2026 14:43:56 +0200 Subject: [PATCH] Update lab-python-functions.ipynb --- lab-python-functions.ipynb | 78 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..f5400ec 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -39,15 +39,85 @@ "\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", + "- Test your functions individually to ensure they work correctly." + ] + }, + { + "cell_type": "markdown", + "id": "58c4307f", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "0cbb8eca", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total order is 3\n", + "percentage is 60.0\n", + "updated inventory is {'t-shirt': 2, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 6}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n", + "\n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for p in products:\n", + " inventory[p] = int(input('Cuántas unidades de ' + p + \":\"))\n", + " return inventory\n", + "\n", + "inventory = initialize_inventory(products)\n", + "\n", + "def get_customer_orders():\n", + " customer_orders = set()\n", + " more = \"yes\"\n", + " while more.lower() == \"yes\":\n", + " order = input(\"Enter a product: \")\n", + " customer_orders.add(order)\n", + " more = input(\"Do you want to add another product? (yes/no): \")\n", + " return customer_orders\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "def update_inventory (customer_orders, inventory):\n", + " for prod in customer_orders:\n", + " if prod in inventory:\n", + " inventory[prod] -=1\n", + " return inventory\n", + "\n", + "inventory= update_inventory(customer_orders, inventory) \n", + "\n", + "def calculate_order_statistics (customer_orders, products):\n", + " total_orders = len(customer_orders)\n", + " percentage = (len(customer_orders)/len (products)) * 100\n", + " return total_orders, percentage\n", + "\n", + "order_statistics = calculate_order_statistics (customer_orders, products)\n", + "\n", + "def print_order_statistics (order_statistics):\n", + " total_orders, percentage = order_statistics\n", + " print (\"total order is \", total_orders)\n", + " print (\"percentage is \", percentage)\n", + "\n", + "print_order_statistics(order_statistics) \n", + "\n", "\n", - "\n" + "def print_updated_inventory (inventory):\n", + " print (\"updated inventory is \", inventory)\n", + "print_updated_inventory (inventory)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +131,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.3" } }, "nbformat": 4,