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
82 changes: 79 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,89 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "76adb064-bc3d-433e-94b4-6bf9ddd168ce",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of t-shirt available: 1\n",
"Enter the quantity of mug available: 1\n",
"Enter the quantity of hat available: 1\n",
"Enter the quantity of book available: 1\n",
"Enter the quantity of keychain available: 1\n",
"Please choose a product from the list ['t-shirt', 'mug', 'hat', 'book', 'keychain']: hat\n",
"Do you want to add another product? yes or no. yes\n",
"Please choose a product from the list ['t-shirt', 'mug', 'hat', 'book', 'keychain']: mug\n",
"Do you want to add another product? yes or no. no\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"You order 40.0% of the inventory.\n",
"The inventory is now: {'t-shirt': 1, 'mug': 0, 'hat': 0, 'book': 1, 'keychain': 1}.\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"def initialize_inventory(products):\n",
" inventory = {product: int(input(f\"Enter the quantity of {product} available: \")) for product in products}\n",
" return inventory\n",
"\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
" add_another = \"yes\"\n",
" while add_another == \"yes\":\n",
" product_order = input(f\"Please choose a product from the list {products}: \")\n",
" customer_orders.add(product_order)\n",
" add_another = input(\"Do you want to add another product? yes or no.\")\n",
" return customer_orders\n",
"\n",
"def update_inventory(customer_orders,inventory):\n",
" for order in customer_orders:\n",
" inventory[order] -= 1\n",
" return inventory\n",
"\n",
"def calculate_order_statistics(customer_orders,products):\n",
" return len(customer_orders)/len(products)*100\n",
"\n",
"def print_order_statistics(order_statistics):\n",
" print(f\"You order {order_statistics}% of the inventory.\")\n",
"\n",
"def print_updated_inventory(update_inventory):\n",
" print(f\"The inventory is now: {update_inventory}.\")\n",
" \n",
"inventory = initialize_inventory(products)\n",
"customer_orders = get_customer_orders()\n",
"updated_inventory = update_inventory(customer_orders,inventory)\n",
"order_statistics = calculate_order_statistics(customer_orders,products)\n",
"print_order_statistics(order_statistics)\n",
"print_updated_inventory(updated_inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "26321be3-3e0b-4fe9-b92c-699e6a865d38",
"metadata": {},
"outputs": [],
"source": []
}
],
"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 +137,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down