Skip to content
Open
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
156 changes: 155 additions & 1 deletion lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,160 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "e8947610-da2c-447b-9a68-bd32b4d9bce7",
"metadata": {},
"outputs": [],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory={} \n",
"def initialize_inventory(products): #1\n",
" \n",
"\n",
" for x in products: \n",
" qnt =input (f\" Enter the inventory quantity of {x}: \")\n",
" inventory[x] = int(qnt)\n",
" return inventory\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "3c8b1d6f-38e0-4dab-b2c5-d3d12adf8f29",
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()\n",
"def get_customer_orders(): #2\n",
" \n",
" answer=\"yes\"\n",
"\n",
" while answer == \"yes\" : \n",
" product = input(\"Enter a product (t-shirt, mug, hat, book, keychain): \") \n",
" customer_orders.add(product) \n",
" answer = input(\"Do you want to add another product? (yes/no): \") \n",
" return customer_orders\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "f016781a-56b1-436f-be04-92bacd2b4e13",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders,inventory): #3\n",
" for product in customer_orders: \n",
" inventory[product] -= 1\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "4a9bc856-f567-4798-ba68-3e204e44e543",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics (customer_orders,products): #4\n",
" \n",
" total_products_ordered = len(customer_orders) \n",
" percentage_products_ordered = (total_products_ordered / len(products)) * 100 \n",
" order_statistics = (total_products_ordered, percentage_products_ordered)\n",
" return order_statistics\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "c733cf1b-8ff8-41d1-93d3-5a3821b7e30e",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics): #5\n",
" total, percentage = order_statistics\n",
" print(\"Order Statistics:\") \n",
" print(f\"Total Products Ordered: {total}\")\n",
" print(f\"Percentage of Products Ordered: {percentage}%\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "5f9f6ca4-88b5-451f-b85d-5a54ed33dfc0",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory): #6\n",
" return inventory\n"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "db8d6253-88ef-41b2-9609-6895f9b54224",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
" Enter the inventory quantity of t-shirt: 8\n",
" Enter the inventory quantity of mug: 9\n",
" Enter the inventory quantity of hat: 45\n",
" Enter the inventory quantity of book: 76\n",
" Enter the inventory quantity of keychain: 4\n",
"Enter a product (t-shirt, mug, hat, book, keychain): hat\n",
"Do you want to add another product? (yes/no): yes\n",
"Enter a product (t-shirt, mug, hat, book, keychain): book\n",
"Do you want to add another product? (yes/no): yes\n",
"Enter a product (t-shirt, mug, hat, book, keychain): mug\n",
"Do you want to add another product? (yes/no): np\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n"
]
},
{
"ename": "NameError",
"evalue": "name 'inventor' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[40], line 7\u001b[0m\n\u001b[1;32m 5\u001b[0m order_statistics \u001b[38;5;241m=\u001b[39m calculate_order_statistics (customer_orders,products)\n\u001b[1;32m 6\u001b[0m print_order_statistics(order_statistics)\n\u001b[0;32m----> 7\u001b[0m \u001b[43mprint_updated_inventory\u001b[49m\u001b[43m(\u001b[49m\u001b[43minventory\u001b[49m\u001b[43m)\u001b[49m\n",
"Cell \u001b[0;32mIn[38], line 2\u001b[0m, in \u001b[0;36mprint_updated_inventory\u001b[0;34m(inventory)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mprint_updated_inventory\u001b[39m(inventory): \u001b[38;5;66;03m#6\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43minventor\u001b[49m\n",
"\u001b[0;31mNameError\u001b[0m: name 'inventor' is not defined"
]
}
],
"source": [
"initialize_inventory(products)\n",
"get_customer_orders()\n",
"update_inventory(customer_orders,inventory)\n",
"calculate_order_statistics (customer_orders,products)\n",
"order_statistics = calculate_order_statistics (customer_orders,products)\n",
"print_order_statistics(order_statistics)\n",
"print_updated_inventory(inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2e5abf70-0746-42e7-b2cd-832f420b4a52",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -61,7 +215,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down