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
89 changes: 86 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,96 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "63afd520-7b15-4433-88c8-248f4bdd43f6",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the number of your book: 2\n",
"Enter the number of your pen: 3\n",
"Enter the number of your notebook: 2\n",
"Enter the number of your hat: 3\n",
"Enter the number of your mug: 54\n",
"Products ordered: book\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total of products ordered are 1 and the percentage of products ordered are 20.00%\n",
"book: 1\n",
"pen: 3\n",
"notebook: 2\n",
"hat: 3\n",
"mug: 54\n"
]
}
],
"source": [
"products = ['book', 'pen', 'notebook', 'hat', 'mug']\n",
"\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for product in products:\n",
" number = int(input(f\"Enter the number of your {product}: \"))\n",
" inventory[product] = number\n",
" return inventory\n",
"\n",
"inventory = initialize_inventory(products)\n",
"\n",
"def get_customer_orders():\n",
" add_order = input(\"Products ordered: \")\n",
" customers_orders = {item.strip() for item in add_order.split(',') if item.strip()}\n",
" return customers_orders\n",
"\n",
"customer_orders = get_customer_orders() \n",
"\n",
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
" return inventory\n",
"inventory = update_inventory(customer_orders, inventory)\n",
"\n",
"def calculate_order_statistics(customer_orders, products):\n",
" total_ordered = len(customer_orders)\n",
" percentage = (total_ordered / len(products)) * 100\n",
" return total_ordered, percentage\n",
"order_stats = calculate_order_statistics(customer_orders, products)\n",
"\n",
"def print_order_statistics(order_statistics):\n",
" total_ordered, percentage = order_statistics\n",
" print(f\"Total of products ordered are {total_ordered} and the percentage of products ordered are {percentage:.2f}%\")\n",
"print_order_statistics(order_stats)\n",
"\n",
"def print_updated_inventory(inventory):\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"print_updated_inventory(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fe57a5fc-d187-496e-bcf4-d4e9a3146a7f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -61,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down