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
216 changes: 213 additions & 3 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,223 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "aaf1c5c1-a090-4987-b099-5fefc888a40c",
"metadata": {},
"outputs": [],
"source": [
"def initialize_inventory (products):\n",
" inventory={}\n",
" for item in products:\n",
" inventory[item]=int(input(f\"quantity of {item} available in the inventory: \"))\n",
" \n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2fe60b8a-cab8-4836-b19f-6f7811294dc5",
"metadata": {},
"outputs": [],
"source": [
"def get_customer_orders():\n",
" customer_orders=set() \n",
" add_another_product=\"yes\"\n",
" \n",
" while add_another_product== \"yes\" :\n",
" x=input(\"input order :\")\n",
" customer_orders.add(x)\n",
" add_another_product=input(\"if you want to add another product (yes/no):\")\n",
" \n",
" return customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "05ac0ed1-3263-4ca4-878e-fb87ddf8e218",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory (customer_orders, inventory ):\n",
" for item in customer_orders:\n",
" inventory[item]=inventory[item]-1\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "4e6d5357-6e82-4f44-b1b5-f1ab6e9838ac",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics (customer_orders, products):\n",
" total_products_ordered=len(customer_orders)\n",
" percentage_ordered=len(customer_orders)/len(products)*100\n",
" order_statistics=(total_products_ordered,percentage_ordered)\n",
" return order_statistics"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "75fdd038-5d04-4ab9-b2ce-7c125c642161",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics (order_statistics ):\n",
" print(\"Order Statistics:\")\n",
" print(f\"Total Products Ordered:{order_statistics[0] }\")\n",
" print(f\"Percentage of Products Ordered:{order_statistics[1]}\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "bbea8abd-b8eb-4765-9cd2-4ef7384b31fb",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory ):\n",
" print (inventory)\n",
" print(inventory.items())\n",
" print(inventory.keys())\n",
" print(inventory.values())\n",
" for item in inventory.items() :\n",
" print(item)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "a35ff804-b525-4aee-b161-fd93bf55a282",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of t-shirt available in the inventory: 20\n",
"quantity of mug available in the inventory: 34\n",
"quantity of hat available in the inventory: 46\n",
"quantity of book available in the inventory: 52\n",
"quantity of keychain available in the inventory: 63\n"
]
}
],
"source": [
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory=initialize_inventory (products)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7afd25dc-b382-4d4f-901a-f78a77c906cb",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"input order : mug\n",
"if you want to add another product (yes/no): yes\n",
"input order : hat\n",
"if you want to add another product (yes/no): no\n"
]
}
],
"source": [
"customer_orders=get_customer_orders()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "752eff20-64f9-42a1-ad78-ae657464d5b8",
"metadata": {},
"outputs": [],
"source": [
"update_inventory (customer_orders, inventory )"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "6ac4887d-25d8-4960-8c27-4c663f4fb39e",
"metadata": {},
"outputs": [],
"source": [
"order_status=calculate_order_statistics (customer_orders, products)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "df70ee9b-4071-44ec-b7f8-fee1b32bb101",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered:2\n",
"Percentage of Products Ordered:40.0\n"
]
}
],
"source": [
"print_order_statistics (order_status)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "34e7ad70-a217-41c5-abba-079db6368835",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 20, 'mug': 32, 'hat': 44, 'book': 52, 'keychain': 63}\n",
"dict_items([('t-shirt', 20), ('mug', 32), ('hat', 44), ('book', 52), ('keychain', 63)])\n",
"dict_keys(['t-shirt', 'mug', 'hat', 'book', 'keychain'])\n",
"dict_values([20, 32, 44, 52, 63])\n",
"('t-shirt', 20)\n",
"('mug', 32)\n",
"('hat', 44)\n",
"('book', 52)\n",
"('keychain', 63)\n"
]
}
],
"source": [
"print_updated_inventory(inventory )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f9e85e1-1599-4df2-8550-2f84797c3d39",
"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 +271,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down