Skip to content
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

lab python_function #322

Open
wants to merge 3 commits 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
59 changes: 59 additions & 0 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,65 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "278fbeb6",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory (products):\n",
" inventory = {}\n",
" for i in products:\n",
" inventory [i] = int(input(f\"What is the quantity of {i}?\"))\n",
" return inventory\n",
"\n",
"def get_customer_orders ():\n",
" customer_orders = set()\n",
" while True:\n",
" products = input(\"What product do you want to order? \")\n",
" if products in products:\n",
" customer_orders.add(products)\n",
" else:\n",
" print(\"Product not in the list\")\n",
" x = input(\"Do you want to add another product (y/n)? \")\n",
" if x.lower() == 'n':\n",
" break\n",
" elif x.lower() != 'y':\n",
" print(\"Please answer with 'y' or 'n'.\")\n",
" return customer_orders\n",
"\n",
"def update_inventory(customer_orders,inventory):\n",
" #update the inventory with the customer order\n",
" for i in customer_orders:\n",
" if i in inventory:\n",
" inventory [i] -=1\n",
"\n",
"def calculate_order_statistics (customer_orders, products):\n",
" Total_Products_Ordered = len(customer_orders)\n",
" Percentage_of_Products_Ordered = len(customer_orders) / len(products) *100 \n",
" order_statistics = (Total_Products_Ordered ,Percentage_of_Products_Ordered)\n",
" return order_statistics\n",
"\n",
"def print_order_statistics (order_statistics):\n",
" print(\"\\nOrder Statistics:\")\n",
" print(\"Total Products Ordered:\", order_statistics[0])\n",
" print(\"Percentage of Unique Products Ordered:\", order_statistics[1])\n",
"\n",
"def print_updated_inventory(inventory):\n",
" print(\"\\nUpdated Inventory:\")\n",
" for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\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