From f09e1b8730241db2312ebf04e5b0913ad466b25c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Beltr=C3=A1n?= Date: Tue, 13 Jan 2026 17:52:12 +0100 Subject: [PATCH] other lab --- lab-python-functions.ipynb | 178 ++++++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..7e816bb 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,185 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 89, + "id": "af6eedc9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 3, 'book': 3, 'hat': 3, 'keychain': 3}\n" + ] + } + ], + "source": [ + "products = [\"t-shirt\", \"mug\", \"book\", \"hat\", \"keychain\"]\n", + "\n", + "def initialized_inventory(products):\n", + " inventory = {}\n", + " for item in products:\n", + " quantity = int(input(f\"Introduce la cantidad de {item}: \"))\n", + "\n", + " inventory[item] = quantity\n", + "\n", + " return inventory\n", + "\n", + "\n", + "inventory = initialized_inventory(products)\n", + "\n", + "print(inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "id": "3e41d458", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thanks for your order\n", + "{'mug', 'hat'}\n" + ] + } + ], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set ()\n", + " \n", + " while True:\n", + " orders = input(\"which product do you want to order?: \")\n", + " customer_orders.add(orders)\n", + "\n", + " continue_buying = input(\"Do you want to order more?: \").lower()\n", + "\n", + " if continue_buying != \"yes\":\n", + " print(\"Thanks for your order\")\n", + " break\n", + "\n", + " return customer_orders\n", + "\n", + "customer_orders = get_customer_orders()\n", + "\n", + "print(customer_orders)\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 93, + "id": "085adf85", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'mug': 1, 'hat': 1}\n" + ] + } + ], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " updated_inventory = {}\n", + "\n", + " for product in customer_orders:\n", + " inventory[product] -= 1\n", + " \n", + " updated_inventory[product]=inventory[product]\n", + " \n", + " return updated_inventory\n", + "\n", + "updated_inventory = update_inventory(customer_orders,inventory)\n", + "\n", + "print(updated_inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 95, + "id": "948a9b34", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 40.0)\n" + ] + } + ], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " \n", + " order_statistics = []\n", + " \n", + " for product in customer_orders:\n", + " total_ordered = len(customer_orders)\n", + " \n", + " for product in products:\n", + " porcentaje = len(customer_orders) / len(products) * 100\n", + "\n", + " return total_ordered, porcentaje\n", + "\n", + "order_statistics = calculate_order_statistics(customer_orders, products)\n", + "\n", + "print(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 99, + "id": "89590aa7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(2, 40.0)\n" + ] + } + ], + "source": [ + "def print_order_statistics(order_statistics):\n", + " return order_statistics\n", + "\n", + "print(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "id": "3ffb71c7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'t-shirt': 3, 'mug': 1, 'book': 3, 'hat': 1, 'keychain': 3}\n" + ] + } + ], + "source": [ + "def print_updated_inventory(inventory):\n", + " return inventory\n", + "\n", + "print(inventory)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -61,7 +235,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,