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
75 changes: 72 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,82 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "966c17a0-8543-41ff-b326-16375b7820cb",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" print(\"Inventory:\")\n",
" for product in products:\n",
" qty = int(input(f\"Enter # of {product}: \"))\n",
" inventory[product] = qty\n",
" return inventory\n",
"\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" print(\"Customer order:\")\n",
" print(\"Available products:\", products)\n",
" add_another = \"yes\"\n",
" while add_another == \"yes\":\n",
" name = input(\"Enter product order: \").strip().lower()\n",
" if name in products:\n",
" customer_orders.add(name)\n",
" print(f\"Added: {name}\")\n",
" else:\n",
" print(\"That product is not available. Please choose from the list.\")\n",
" add_another = input(\"Do you want to add another product? (yes/no): \").strip().lower()\n",
" return customer_orders\n",
"\n",
"def update_inventory(customer_orders, inventory):\n",
" for product in products:\n",
" if product in customer_orders:\n",
" inventory[product] -= 1\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",
"\n",
"def print_order_statistics(order_statistics):\n",
" total_ordered, percentage = order_statistics\n",
" print(\"Order Statistics:\")\n",
" print(\"Total Products Ordered:\", total_ordered)\n",
" print(\"Percentage of Unique Products Ordered:\", percentage, \"%\")\n",
"\n",
"def print_updated_inventory(inventory):\n",
" print(\"Updated inventory after the order:\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"inventory = initialize_inventory(products)\n",
"customer_orders = get_customer_orders()\n",
"update_inventory(customer_orders, inventory)\n",
"stats = calculate_order_statistics(customer_orders, products)\n",
"print_order_statistics(stats)\n",
"print_updated_inventory(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "562ea1d0-aa35-4fc0-bf8b-02352e72b413",
"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 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down