Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 157 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,166 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "dcc1c843",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for i in products:\n",
" cantidad = int(input(f\"Ingresa la cantidad disponible para '{i}': \"))\n",
" inventory[i] = cantidad\n",
" return inventory\n",
"\n",
"inventory = initialize_inventory(products)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "6e67e815",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set() \n",
" seguir_comprando = input(\"¿Quieres comprar algo ? yes or no: \").lower()\n",
" while seguir_comprando == \"yes\":\n",
" product = input(\"Introduce lo que vas a comprar: \")\n",
" customer_orders.add(product)\n",
" seguir_comprando = input(\"¿Quieres seguir comprando? yes or no: \").lower()\n",
" \n",
" return customer_orders\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "26a198c4",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders , inventory):\n",
" for i in customer_orders:\n",
" inventory[i] -= 1\n"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "4f739ec5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'mug'}"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "7f75a048",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
" order_statistics = len(customer_orders)\n",
" percentage_of_unique = (len(customer_orders) / len(products)) * 100\n",
" return order_statistics, percentage_of_unique\n"
]
},
{
"cell_type": "code",
"execution_count": 64,
"id": "c4d479a9",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" total_products_ordered, percentage_unique_products = order_statistics\n",
" print(f\"Total de productos pedidos: {total_products_ordered}\")\n",
" print(f\"Porcentaje de productos únicos pedidos: {percentage_unique_products}%\")\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "f7d48533",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" for product, cantidad in inventory.items():\n",
" print(f\"{product}: {cantidad}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a26c3e1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total de productos pedidos: 2\n",
"Porcentaje de productos únicos pedidos: 40.0%\n",
"t-shirt: 50\n",
"mug: 39\n",
"hat: 50\n",
"book: 39\n",
"keychain: 30\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = initialize_inventory(products)\n",
"\n",
"customer_orders = get_customer_orders()\n",
"\n",
"update_inventory(customer_orders, inventory)\n",
"\n",
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"\n",
"print_order_statistics(order_statistics)\n",
"\n",
"print_updated_inventory(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b06543eb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +216,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down