Skip to content
Open

lab3 #594

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
90 changes: 88 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,97 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "ee6b45e4",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory(products):\n",
" inventory = {}\n",
"\n",
" for product in products:\n",
" quantity = int(input(\"Enter quantity for product:\"))\n",
" inventory[product] = quantity\n",
"\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "31e6e5cc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'hat', 'keychain'}\n"
]
}
],
"source": [
"def get_customer_orders():\n",
" customer_orders = set()\n",
"\n",
" while True:\n",
" product = input(\"Enter product name: \")\n",
" customer_orders.add(product)\n",
"\n",
" choice = input(\"Do you want to enter another product? (yes/no): \")\n",
"\n",
" if choice.lower() == \"no\":\n",
" break\n",
"\n",
" return customer_orders\n",
"orders = get_customer_orders()\n",
"print(orders)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "a53e7adb",
"metadata": {},
"outputs": [],
"source": [
"\n",
"inventory={'t-shirt': 5, 'mug': 4, 'hat': 3, 'book': 2, 'keychain': 1}\n",
"customer_orders={'hat','keychain'}\n",
"def update_inventory(customer_orders, inventory):\n",
" for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
" print(update_inventory)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b5222c71",
"metadata": {},
"outputs": [],
"source": [
"customer_order = {'hat', 'keychain'}\n",
"products = {'t-shirt', 'mug', 'hat', 'book', 'keychain'}\n",
"\n",
"def calculate_order_statistics(customer_order, products):\n",
" total_product_ordered = len(customer_order)\n",
" percentage_ordered = (total_product_ordered / len(products)) * 100\n",
" return total_product_ordered, percentage_ordered\n",
"print(total_product_ordered)\n",
"print(percentage_ordered)\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +147,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down