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
162 changes: 160 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,169 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "2e530946",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "3bef3da7",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" inventory = {}\n",
"\n",
" for product in products:\n",
"\n",
" quantity = int(input(\"Enter the quantity of \" + product + \": \"))\n",
" inventory[product] = quantity\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "1f7e4771",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set()\n",
" sigue_añadiendo = \"si\"\n",
"\n",
" while sigue_añadiendo == \"si\":\n",
" producto = input(\"Dime un producto que quieras pedir: \")\n",
" \n",
" if producto in products:\n",
" customer_orders.add(producto)\n",
" else:\n",
" print(\"Este producto no está disponible\")\n",
" sigue_añadiendo = input(\"¿Quieres añadir otro producto? (Si/No): \").lower()\n",
"\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "6e56f88d",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = get_customer_orders()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "5b1ae574",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" inventory[product] = inventory[product] - 1 \n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "3f3bc2f9",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
"\n",
" total_products_ordered = len(customer_orders)\n",
"\n",
" percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
" order_statistics = (total_products_ordered, percentage_ordered)\n",
"\n",
" return order_statistics"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "df2590e4",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
"\n",
" print(\"Order Statistics:\")\n",
" print(\"Total Products Ordered:\", order_statistics[0])\n",
" print(\"Percentage of Products Ordered:\", order_statistics[1], \"%\")"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "208cb93c",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
"\n",
" print(\"Updated Inventory:\")\n",
"\n",
" for product in inventory:\n",
" print(product, \":\", inventory[product])"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "03ca8ea6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Este producto no está disponible\n",
"Este producto no está disponible\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n",
"Updated Inventory:\n",
"t-shirt : 15\n",
"mug : 10\n",
"hat : 19\n",
"book : 24\n",
"keychain : 29\n"
]
}
],
"source": [
"inventory = initialize_inventory(products)\n",
"\n",
"customer_orders = get_customer_orders()\n",
"\n",
"inventory = 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)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.6"
}
},
"nbformat": 4,
Expand Down