From e2177f0cf799e2bf1ca4560a3d17f0f6823d2b2e Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Tue, 13 Jan 2026 16:03:00 +0100 Subject: [PATCH] updated-lab-functions --- lab-python-functions.ipynb | 225 ++++++++++++++++++++++++++++++++++++- 1 file changed, 223 insertions(+), 2 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..b5cdf7a 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -43,11 +43,232 @@ "\n", "\n" ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "a0158c52", + "metadata": {}, + "outputs": [], + "source": [ + "products = ['t-shirt', 'mug', 'hat', 'book', 'keychain']" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "482559d0", + "metadata": {}, + "outputs": [], + "source": [ + "#Define initialize_inventory \n", + "def initialize_inventory(products):\n", + " inventory = {}\n", + " for product in products:\n", + " quantity = int(input(f\"Enter the quantity for {product}: \"))\n", + " inventory[product] = quantity\n", + " \n", + " return inventory" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "0e61bfa0", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " customer_orders = set()\n", + "\n", + " while True:\n", + " product = input(\"Enter a product to order; \")\n", + " if product in products:\n", + " customer_orders.add(product)\n", + " else:\n", + " print(\"Product no available. Choose from:\", products)\n", + "\n", + " add_more = input(\"Do you want to add another product?(yes/no): \").lower()\n", + " if add_more == 'no':\n", + " break\n", + " \n", + " return customer_orders" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "59a84e80", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders, inventory):\n", + " for product in customer_orders:\n", + " if product in inventory:\n", + " inventory[product] -= 1" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "91282543", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders, products):\n", + " total_ordered = len(customer_orders)\n", + " percentage_order = (total_ordered / len(products)) *100\n", + " order_statistics = (total_ordered, percentage_order)\n", + " return total_ordered, percentage_order, order_statistics" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "8890e414", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " print(\"Order Statistics: \")\n", + " print(f\"Total Products Ordered: {order_statistics[0]}\")\n", + " print(f\"Percentage of Products Ordered: {order_statistics[1]}%\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "b251c136", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(\"Updated Inventary: \")\n", + " for product, quantity in inventory.items():\n", + " print(f\"{product}: {quantity}\")" + ] + }, + { + "cell_type": "markdown", + "id": "17d732fe", + "metadata": {}, + "source": [ + "Llamando a las funciones" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "488c54a3", + "metadata": {}, + "outputs": [], + "source": [ + "inventory = initialize_inventory(products)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "7cb804fd", + "metadata": {}, + "outputs": [], + "source": [ + "customer_orders = get_customer_orders()" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "732dd5df", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Customer Oder: {'hat', 'book', 'keychain'}\n" + ] + } + ], + "source": [ + "print(\"Customer Oder: \", customer_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "9058e104", + "metadata": {}, + "outputs": [], + "source": [ + "order_statistics = calculate_order_statistics(customer_orders, products)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "29a2af3e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Order Statistics: \n", + "Total Products Ordered: 3\n", + "Percentage of Products Ordered: 60.0%\n" + ] + } + ], + "source": [ + "print_order_stat = print_order_statistics(order_statistics)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "dd0c9626", + "metadata": {}, + "outputs": [], + "source": [ + "update_inventory(customer_orders, inventory)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "f76a0a40", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated Inventary: \n", + "t-shirt: 5\n", + "mug: 5\n", + "hat: 4\n", + "book: 4\n", + "keychain: 4\n" + ] + } + ], + "source": [ + "print_updated_inventory(inventory)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0c772d1b", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +282,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.10.2" } }, "nbformat": 4,