Skip to content

Added Solution #435

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
151 changes: 148 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,158 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "871628ae-e4d6-4db2-938f-dc9860659f33",
"metadata": {},
"outputs": [],
"source": [
"#1.\n",
"def initialize_inventory(products):\n",
" inventory={}\n",
" for product in products:\n",
" inventory[product]=int(input(f\"Enter the number of available {product}\"))\n",
" return inventory\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "279357e0-b2e7-4b5e-a4e2-f35ef7b11a48",
"metadata": {},
"outputs": [],
"source": [
"#2.\n",
"\n",
"def get_customer_orders():\n",
" customer_orders=set() #set\n",
" choice=\"yes\"\n",
" while choice.lower() == \"yes\":\n",
" customer_orders.add(input(f\"Enter a product that you want to order from {products} \"))\n",
" choice= input(\"Do you want to add another product (yes/no)\")\n",
" return customer_orders\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "5f78783d-bee6-48a2-a628-767fc886837d",
"metadata": {},
"outputs": [],
"source": [
"#3.\n",
"def update_inventory(customer_orders,inventory):\n",
" for customer_order in customer_orders:\n",
" if customer_order in inventory and inventory[customer_order]>0:\n",
" inventory[customer_order]=inventory[customer_order]-1\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "f9bb5c26-84b6-4501-884a-a11abf8df88d",
"metadata": {},
"outputs": [],
"source": [
"#4.\n",
"def calculate_order_statistics(customer_orders,products):\n",
" total_products_ordered=len(customer_orders)\n",
" percentage_ordered =100*total_products_ordered/len(products)\n",
" order_statistics=(total_products_ordered,percentage_ordered)\n",
" return order_statistics\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "5639cd02-c8ed-468d-85f7-f1f936a7bc3a",
"metadata": {},
"outputs": [],
"source": [
"#5.\n",
"def print_order_statistics(order_statistics):\n",
" print(\"Order Statistics:\")\n",
" print(f\"Total Products Ordered: {order_statistics[0]}\")\n",
" print(f\"Percentage of Products Ordered: {order_statistics[1]}% \")\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "19df2eb6-9119-441b-a4a8-d46930f6fa75",
"metadata": {},
"outputs": [],
"source": [
"#6.\n",
"def print_updated_inventory(inventory):\n",
" for key,value in inventory.items():\n",
" print(f\"{key}-{value}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "db12a6b1-fd18-4b70-971f-65af20da227d",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the number of available t-shirt 8\n",
"Enter the number of available mug 5\n",
"Enter the number of available hat 6\n",
"Enter the number of available book 2\n",
"Enter the number of available keychain 1\n",
"Enter a product that you want to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] t-shirt\n",
"Do you want to add another product (yes/no) yes\n",
"Enter a product that you want to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
"Do you want to add another product (yes/no) yes\n",
"Enter a product that you want to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n",
"Do you want to add another product (yes/no) yes\n",
"Enter a product that you want to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n",
"Do you want to add another product (yes/no) no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 4\n",
"Percentage of Products Ordered: 80.0% \n",
"t-shirt-7\n",
"mug-4\n",
"hat-5\n",
"book-1\n",
"keychain-1\n"
]
}
],
"source": [
"#7.\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #products list\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": {
"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 +206,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down