Skip to content

lab 3 OK #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
73 changes: 73 additions & 0 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,79 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c7a17d0",
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"#1\n",
"def initialize_inventory(products):\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"Enter quantity product {product}: \"))\n",
" inventory[product] = quantity\n",
" return inventory \n",
"\n",
"#2\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" print(\"Enter the product you want to order.\")\n",
" print (\"Type OK when it's ok.\")\n",
" while True:\n",
" order = input(\"Product name: \")\n",
" if order.lower() == \"OK\":\n",
" break\n",
" customer_orders.add(order)\n",
" return customer_orders\n",
"\n",
"#3\n",
"def update_inventory(customer_orders, inventory):\n",
" for order in customer_orders:\n",
" if order in inventory and inventory[order] > 0:\n",
" inventory [order] -= 1\n",
"\n",
"#4\n",
"def calculate_order_statistics(customer_orders, products):\n",
" total_products_ordered = len(customer_orders)\n",
" percent_unique_product = (total_products_ordered / len(products)) * 100 if products else 0\n",
" return total_products_ordered, percent_unique_product\n",
"\n",
"#5\n",
"def print_order_statistics (order_statistics):\n",
" total_products_ordered, percent_unique_product = order_statistics\n",
" print (f\"Order Statistics:\")\n",
" print (f\"Total of the products ordered : {total_products_ordered}\")\n",
" print (f\"Percentage of unique products ordered: {percent_unique_product:.2f}%\")\n",
"\n",
"#6\n",
"def print_updated_inventory(inventory):\n",
" print(\"Updated Inventory\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product: {quantity}}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c03ac5e7",
"metadata": {},
"outputs": [],
"source": [
"def exe():\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",
" print_order_statistics(order_statistics)\n",
" print_updated_inventory(inventory)"
]
}
],
"metadata": {
Expand Down