Skip to content

lab complete #439

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
152 changes: 151 additions & 1 deletion lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,156 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "200defb6-e54d-4685-b2b9-069f193b637c",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory (list_products):\n",
" for product in list_products :\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f47515b1-dcf4-4f65-8d7d-953c31c0d80c",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" customer_status = True\n",
" while customer_status == True:\n",
" customer_orders.add(input(f\"Enter the name of a product that the customer wants : {list_products}\"))\n",
" customer_answer = (input(f\" Want to do another purchase, answser : yes or no\"))\n",
" if customer_answer == \"yes\" :\n",
" customer_status = True\n",
" else :\n",
" customer_status = False\n",
" break\n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "71eaf890-b49f-468f-872a-0db03fdddb5f",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" if product in inventory and inventory[product] > 0:\n",
" inventory[product] -= 1\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "28d6cde5-cc58-4f28-8e51-194f33dd7e71",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics (customer_orders,list_products,inventory) :\n",
" order_statistics = {}\n",
" total_prod_ordered = len(customer_orders)\n",
" order_statistics[\"total_prod_ordered\"] = total_prod_ordered\n",
" \n",
" total_inventory = sum(inventory.values())\n",
" percentage_products_ordered = (total_prod_ordered / total_inventory)*100\n",
" order_statistics [\"percentage_products_ordered\"] = percentage_products_ordered\n",
" return order_statistics"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "0b27bd5d-1d7d-46af-9326-0c5d4b486947",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics (order_statistics):\n",
" print(f\"Total Products Ordered: {order_statistics[\"total_prod_ordered\"]}.\")\n",
" print(f\"Percentage of Products Ordered: {order_statistics[\"percentage_products_ordered\"]:.2f}%. \")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "1aad97d7-d883-41ad-b3c2-d58116c87d81",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory (inventory) :\n",
" print(f\"This is the inventory after customer order :\")\n",
" for product, quantity in inventory.items():\n",
" print (f\"{product} : {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "08c098ac-4209-4627-8125-0e90b4aa140d",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of t-shirt: 1\n",
"Enter the quantity of mug: 2\n",
"Enter the quantity of hat: 3\n",
"Enter the quantity of book: 4\n",
"Enter the quantity of keychain: 5\n",
"Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
" Want to do another purchase, answser : yes or no yes\n",
"Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n",
" Want to do another purchase, answser : yes or no yes\n",
"Enter the name of a product that the customer wants : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n",
" Want to do another purchase, answser : yes or no no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3.\n",
"Percentage of Products Ordered: 25.00%. \n",
"This is the inventory after customer order :\n",
"t-shirt : 1\n",
"mug : 1\n",
"hat : 2\n",
"book : 3\n",
"keychain : 5\n"
]
}
],
"source": [
"list_products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"initialize_inventory(list_products)\n",
"customer_orders = get_customer_orders()\n",
"update_inventory(customer_orders, inventory)\n",
"order_statistics = calculate_order_statistics (customer_orders,list_products,inventory)\n",
"print_order_statistics (order_statistics)\n",
"print_updated_inventory (inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ccf9fb62-6df1-49c0-ae16-6a6f09c6a72e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -61,7 +211,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down