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
78 changes: 74 additions & 4 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,85 @@
"\n",
"- Consider the input parameters required for each function and their return values.\n",
"- Utilize function parameters and return values to transfer data between functions.\n",
"- Test your functions individually to ensure they work correctly.\n",
"- Test your functions individually to ensure they work correctly."
]
},
{
"cell_type": "markdown",
"id": "58c4307f",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 36,
"id": "0cbb8eca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total order is 3\n",
"percentage is 60.0\n",
"updated inventory is {'t-shirt': 2, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 6}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for p in products:\n",
" inventory[p] = int(input('Cuántas unidades de ' + p + \":\"))\n",
" return inventory\n",
"\n",
"inventory = initialize_inventory(products)\n",
"\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" more = \"yes\"\n",
" while more.lower() == \"yes\":\n",
" order = input(\"Enter a product: \")\n",
" customer_orders.add(order)\n",
" more = input(\"Do you want to add another product? (yes/no): \")\n",
" return customer_orders\n",
"\n",
"customer_orders = get_customer_orders()\n",
"\n",
"def update_inventory (customer_orders, inventory):\n",
" for prod in customer_orders:\n",
" if prod in inventory:\n",
" inventory[prod] -=1\n",
" return inventory\n",
"\n",
"inventory= update_inventory(customer_orders, inventory) \n",
"\n",
"def calculate_order_statistics (customer_orders, products):\n",
" total_orders = len(customer_orders)\n",
" percentage = (len(customer_orders)/len (products)) * 100\n",
" return total_orders, percentage\n",
"\n",
"order_statistics = calculate_order_statistics (customer_orders, products)\n",
"\n",
"def print_order_statistics (order_statistics):\n",
" total_orders, percentage = order_statistics\n",
" print (\"total order is \", total_orders)\n",
" print (\"percentage is \", percentage)\n",
"\n",
"print_order_statistics(order_statistics) \n",
"\n",
"\n",
"\n"
"def print_updated_inventory (inventory):\n",
" print (\"updated inventory is \", inventory)\n",
"print_updated_inventory (inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +131,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.3"
}
},
"nbformat": 4,
Expand Down