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
156 changes: 154 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,163 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "aa74bd95",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 1, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"def initialize_inventory(products):\n",
" for product in products:\n",
" \"\"\" Prompt the user to enter the inventory count for each product and store it in the inventory dictionary.\"\"\"\n",
" inventory[product] = int(input(f\"Enter the inventory count for {product}: \"))\n",
" return inventory\n",
"\n",
"initialize_inventory(products)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "449e23b5",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders = set() #to set up an empty set, could also be {}, but it gave me an error\n",
"\n",
" while input(\"Do you want to place an order? (yes/no): \").lower() == \"yes\":\n",
" customer_orders.add(input(\"Enter one order (from `t-shirt`, `mug`, `hat`, `book`, `keychain`): \"))\n",
"\n",
" return customer_orders\n",
"\n",
"customer_orders = get_customer_orders()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "621b5828",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 1, 'mug': 0, 'hat': 1, 'book': 4, 'keychain': 5}\n"
]
}
],
"source": [
"def update_inventory(inventory, customer_orders):\n",
" for product in customer_orders:\n",
" if product in inventory and inventory[product] > 0:\n",
" inventory[product] -= 1\n",
" return inventory\n",
"\n",
"update_inventory(inventory, customer_orders)\n",
"#print (inventory)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "e478ce61",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders, products):\n",
" total_products_ordered = len(customer_orders)\n",
" total_in_house = sum(inventory.values())\n",
" percentage_ordered = (total_products_ordered / total_in_house) * 100\n",
" order_status = (total_products_ordered, percentage_ordered)\n",
" return total_products_ordered, total_in_house, percentage_ordered, order_status\n",
"\n",
"total_products_ordered, total_in_house, percentage_ordered, order_statistics = calculate_order_statistics(customer_orders, products)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6a2e7a02",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Order Statistics:\n",
" Total Products Ordered: 2\n",
" Percentage of Products Ordered: 18.181818181818183% \n",
" \n"
]
}
],
"source": [
"def print_order_statistics(order_statistics):\n",
" print(f\"\"\"\n",
" Order Statistics:\n",
" Total Products Ordered: {total_products_ordered}\n",
" Percentage of Products Ordered: {percentage_ordered}% \n",
" \"\"\")\n",
" \n",
"print_order_statistics(order_statistics)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "04b355db",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory:\n",
" t-shirt: 1\n",
" mug: 0\n",
" hat: 1\n",
" book: 4\n",
" keychain: 5\n",
" \n"
]
}
],
"source": [
"def print_updated_inventory(inventory):\n",
" print(f\"\"\"Updated Inventory:\n",
" t-shirt: {inventory['t-shirt']}\n",
" mug: {inventory['mug']}\n",
" hat: {inventory['hat']}\n",
" book: {inventory['book']}\n",
" keychain: {inventory['keychain']}\n",
" \"\"\")\n",
" \n",
"print_updated_inventory(inventory)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +213,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down