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
87 changes: 86 additions & 1 deletion lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,91 @@
"# Lab | Functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with '/opt/homebrew/bin/python3' requires the ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/opt/homebrew/bin/python3 -m pip install ipykernel -U --user --force-reinstall'"
]
}
],
"source": [
"# Step1\n",
"def initialize_inventory(products) :\n",
" inventory = {}\n",
" for product in products:\n",
" quantity = int(input(f\"Enter the quantity available for the product : \"))\n",
" inventory[product] = quantity\n",
" return inventory\n",
"\n",
"# Step 2\n",
"def get_customer_orders():\n",
" customer_orders = set()\n",
"\n",
" while True :\n",
" product = input(\"Enter a product to enter : \") \n",
" customer_orders.add(product)\n",
"\n",
" more_order = input(\"Do you want to add another product? (yes/no) : \")\n",
" if more_order.lower() == \"no\" :\n",
" break\n",
"\n",
" return customer_orders\n",
"\n",
"# Step 3\n",
"\n",
"def update_inventory(customer_orders,inventory):\n",
" for product in customer_orders :\n",
" if product in inventory :\n",
" inventory[product] -= 1\n",
" return inventory\n",
"\n",
"# Step 4\n",
"\n",
"def calculate_order_statistics(customer_orders, products) :\n",
" total_products_order = len(customer_orders)\n",
" percentage_ordered = (total_products_order / len(products)) * 100\n",
" return total_products_order, percentage_ordered\n",
"\n",
"# Step 5 \n",
"\n",
"def print_order_statistics(order_statistics) : \n",
" print(order_statistics)\n",
" print(\"Total products ordered\", order_statistics[0])\n",
" print(\"Percentage of products ordered\", order_statistics[1], \"%\")\n",
"\n",
"# Step 6\n",
"\n",
"def print_updated_inventory(inventory) :\n",
" print(\"Updated_inventory : \")\n",
" for product, quantity in inventory.items()\n",
" print(product, \":\" , quantity)\n",
"\n",
"# Step 7\n",
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = initialize_inventory(products)\n",
"\n",
"customer_orders = get_customer_orders()\n",
"\n",
"total_products_ordered, percentage_ordered = calculate_order_statistics(customer_orders, products)\n",
"\n",
"order_statistics = (total_products_ordered,percentage_ordered)\n",
"\n",
"print_order_statistics(order_statistics)\n",
"\n",
"print(update_inventory)\n"
]
},
{
"cell_type": "markdown",
"id": "0c581062-8967-4d93-b06e-62833222f930",
Expand Down Expand Up @@ -61,7 +146,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down