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
86 changes: 84 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,93 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e8c11325",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Available products: t-shirt, mug, hat, book, keychain\n",
"\n",
"Order Statistics:\n",
"Total Products Ordered: 2\n",
"Percentage of Products Ordered: 40.0 %\n",
"\n",
"Updated Inventory:\n",
"t-shirt: 56\n",
"mug: 82\n",
"hat: 70\n",
"book: 64\n",
"keychain: 55\n"
]
}
],
"source": [
"#1.\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for item in products:\n",
" quantity = int(input(f\"Enter quantity for '{item}': \"))\n",
" inventory[item] = quantity\n",
" return inventory\n",
"\n",
"#2.\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" print(\"\\nAvailable products: t-shirt, mug, hat, book, keychain\")\n",
" continue_ordering = \"yes\"\n",
" while continue_ordering == \"yes\":\n",
" product_name = input(\"Enter the name of a product you want to order: \")\n",
" customer_orders.add(product_name)\n",
" continue_ordering = input(\"Do you want to add another product? (yes/no): \")\n",
" return customer_orders\n",
"\n",
"#3.\n",
"def update_inventory(customer_orders, inventory):\n",
" for item in customer_orders:\n",
" if item in inventory:\n",
" inventory[item] -= 1\n",
"\n",
"#4.\n",
"def calculate_order_statistics(customer_orders, products):\n",
" total_products_ordered = len(customer_orders)\n",
" percentage_ordered = (total_products_ordered / len(products)) * 100\n",
" return (total_products_ordered, percentage_ordered)\n",
"\n",
"#5.\n",
"def print_order_statistics(order_statistics):\n",
" print(\"\\nOrder Statistics:\")\n",
" print(\"Total Products Ordered:\", order_statistics[0])\n",
" print(\"Percentage of Products Ordered:\", order_statistics[1], \"%\") \n",
"\n",
"#6.\n",
"def print_updated_inventory(inventory):\n",
" print(\"\\nUpdated Inventory:\")\n",
" for item, qty in inventory.items():\n",
" print(f\"{item}: {qty}\")\n",
"\n",
"#7.\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = initialize_inventory(products)\n",
"customer_orders = get_customer_orders()\n",
"update_inventory(customer_orders, inventory)\n",
"order_statistics = calculate_order_statistics(customer_orders, products)\n",
"\n",
"print_order_statistics(order_statistics)\n",
"print_updated_inventory(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down