From fb9235840ff2956b03ba2bbf607d8c502a9fc845 Mon Sep 17 00:00:00 2001 From: demonvaa Date: Tue, 14 Apr 2026 16:34:26 +0200 Subject: [PATCH] Update lab-python-functions.ipynb Resolucion 14042026 16.34 --- lab-python-functions.ipynb | 282 ++++++++++++++++++++++++++++++++++++- 1 file changed, 278 insertions(+), 4 deletions(-) diff --git a/lab-python-functions.ipynb b/lab-python-functions.ipynb index 44d337b..ec86af9 100644 --- a/lab-python-functions.ipynb +++ b/lab-python-functions.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "25d7736c-ba17-4aff-b6bb-66eba20fbf4e", + "id": "9bfdb4e3", "metadata": {}, "source": [ "# Lab | Functions" @@ -23,7 +23,7 @@ "\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", + "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 (por ejemplo me va a quitar 5 unidades) 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", @@ -43,11 +43,285 @@ "\n", "\n" ] + }, + { + "cell_type": "markdown", + "id": "b94b400a", + "metadata": {}, + "source": [ + "---" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "60697b8f", + "metadata": {}, + "outputs": [], + "source": [ + "# primero voy a ver que quiero hacer en el inventario creando una lista de productos\n", + "\n", + "def lista_productos():\n", + " lista_terminada = 'no'\n", + " productos = []\n", + " while lista_terminada == 'no':\n", + " productos.append(input(\"Que aƱadimos a la lista\"))\n", + " lista_terminada = input(\"Has acabado la lista: yes/no\").lower()\n", + " return productos\n" + ] + }, + { + "cell_type": "markdown", + "id": "26e05a58", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "3f43143e", + "metadata": {}, + "outputs": [], + "source": [ + "def initialize_inventory(products):\n", + " inventario_completo = \"no\"\n", + " inventory = {}\n", + " while inventario_completo == 'no':\n", + " for x in products:\n", + " cantidad_producto = int(input(f\"Dime la cantidad de {x} que hay \"))\n", + " inventory[x] = cantidad_producto\n", + " inventario_completo = 'yes'\n", + " return inventory" + ] + }, + { + "cell_type": "markdown", + "id": "d8fb9326", + "metadata": {}, + "source": [ + "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 (por ejemplo me va a quitar 5 unidades) using a loop. The function should return the `customer_orders` set. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a8390d3f", + "metadata": {}, + "outputs": [], + "source": [ + "def get_customer_orders():\n", + " pedido_completado = \"no\"\n", + " customer_orders = set()\n", + "\n", + " while pedido_completado != 'yes': \n", + " customer_orders.add(input(f\"tienes {inventario} disponible...Dime que quieres pedir\"))\n", + " pedido_completado = input(f\"Has terminado con el pedido yes/no\").lower()\n", + " return customer_orders \n" + ] + }, + { + "cell_type": "markdown", + "id": "b0dd4c00", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "5b4fa531", + "metadata": {}, + "outputs": [], + "source": [ + "def update_inventory(customer_orders ,inventory ):\n", + " for x in customer_orders:\n", + " inventory[x] -= 5\n", + " return inventory" + ] + }, + { + "cell_type": "markdown", + "id": "75082912", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "680837a0", + "metadata": {}, + "outputs": [], + "source": [ + "def calculate_order_statistics(customer_orders,products):\n", + " total_products_ordered = len(customer_orders)\n", + " unique_product = len(products)\n", + " percentage_of_unique_products_ordered = round((total_products_ordered /unique_product)*100,2)\n", + " return total_products_ordered, percentage_of_unique_products_ordered" + ] + }, + { + "cell_type": "markdown", + "id": "eac53734", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "184a7724", + "metadata": {}, + "outputs": [], + "source": [ + "def print_order_statistics(order_statistics):\n", + " ordenes_totales, porcentaje_de_productos_pedidos = order_statistics\n", + " print(f\"ordenes_totales {ordenes_totales}\")\n", + " print(f\"porcentaje de productos pedidos = {porcentaje_de_productos_pedidos} %\")" + ] + }, + { + "cell_type": "markdown", + "id": "2d2c9700", + "metadata": {}, + "source": [ + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "038c0116", + "metadata": {}, + "outputs": [], + "source": [ + "def print_updated_inventory(inventory):\n", + " print(inventory)" + ] + }, + { + "cell_type": "markdown", + "id": "8c6ea5cf", + "metadata": {}, + "source": [ + "7. Call the functions in the appropriate sequence to execute the program and manage customer orders." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "7229f5f8", + "metadata": {}, + "outputs": [], + "source": [ + "productos_inventario = lista_productos()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "9ed06252", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['manzanas', 'peras', 'limones', 'uvas']\n" + ] + } + ], + "source": [ + "print(productos_inventario)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5a426063", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'manzanas': 40, 'peras': 50, 'limones': 60, 'uvas': 70}\n" + ] + } + ], + "source": [ + "inventario = initialize_inventory(productos_inventario)\n", + "print(inventario)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "a6760d4b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Has pedido {'peras', 'limones'} en tu pedido. Se descontaran 5 de cada una\n" + ] + } + ], + "source": [ + "ordenes_clientes_elementos = get_customer_orders()\n", + "print(f\"Has pedido {ordenes_clientes_elementos} en tu pedido. Se descontaran 5 de cada una\")\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "e49acf84", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ordenes_totales 2\n", + "porcentaje de productos pedidos = 50.0 %\n" + ] + } + ], + "source": [ + "ordenes_estadisticas = calculate_order_statistics(ordenes_clientes_elementos,productos_inventario)\n", + "print_order_statistics(ordenes_estadisticas)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "eaec9b4a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'manzanas': 40, 'peras': 45, 'limones': 55, 'uvas': 70}\n" + ] + } + ], + "source": [ + "inventario_actualizado = update_inventory(ordenes_clientes_elementos,inventario)\n", + "print_updated_inventory(inventario_actualizado)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -61,7 +335,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.2" } }, "nbformat": 4,