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
94 changes: 92 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,101 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "88697088",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products): #defines the starting inventory and its products\n",
" inventory = {}\n",
" print(\"quantity available of each product:\")\n",
" for item in products:\n",
" while True:\n",
" quantity = input(f\" {item}: \").strip()\n",
" if quantity.isdigit(): \n",
" inventory[item] = int(quantity)\n",
" break\n",
" print(\" please enter a non-negative number.\") \n",
" return inventory #initializes the inventory with user input"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "d15eadfc",
"metadata": {},
"outputs": [],
"source": [
"def get_costumer_orders(): #takes the orders from the costumers without parameters\n",
" customer_orders = set()\n",
" add_another = 'y'\n",
" while add_another.lower() == 'y':\n",
" product_name = input(\"Enter the product name to order: \")\n",
" customer_orders.add(product_name)\n",
" add_another = input(\"Do you want to add another product? (y/n): \")\n",
" return customer_orders #returns the set of ordered products\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "c8d1e647",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(inventory, orders): #updates the inventory based on the orders taken\n",
" for item in products:\n",
" if item in orders:\n",
" inventory[item] -= orders[item]\n",
" return inventory #returns the updated inventory"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "e1045362",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statitics(customer_orders, products): #calculates the total items ordered and the average items per product\n",
" total_products_ordered = len(customer_orders)\n",
" percentage_ordered = (total_products_ordered / len(products)) * 100\n",
" return total_products_ordered, percentage_ordered #returns the total items ordered and the average"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "37c05593",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(total_products_ordered, percentage_ordered): #prints the order statistics\n",
" print(f\"Total products ordered: {total_products_ordered}\")\n",
" print(f\"Percentage of products ordered: {percentage_ordered:.2f}%\")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "ff04cbd2",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory): #prints the updated inventory\n",
" print(\"Updated inventory:\")\n",
" for item in products:\n",
" print(f\" {item}: {inventory[item]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +151,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down