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
176 changes: 174 additions & 2 deletions lab-python-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,183 @@
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 135,
"id": "aed5288b",
"metadata": {},
"outputs": [],
"source": [
"products=[\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n",
"\n",
"def initialize_inventory(products):\n",
" inventory={}\n",
" for product in products:\n",
" user_input=int(input(\"enter the quanity\"))\n",
" inventory[product]=user_input\n",
" return inventory\n",
" \n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 136,
"id": "bf722284",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}"
]
},
"execution_count": 136,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"initialize_inventory(products)"
]
},
{
"cell_type": "code",
"execution_count": 137,
"id": "10a36a48",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def get_customer_orders():\n",
" customer_orders=set()\n",
" for i in range(3):\n",
" user_input=input(\"enter the name of the product\")\n",
" customer_orders.add(user_input)\n",
" return customer_orders\n"
]
},
{
"cell_type": "code",
"execution_count": 138,
"id": "ef7a8ec9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'book', 'hat', 'mug'}"
]
},
"execution_count": 138,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"get_customer_orders()"
]
},
{
"cell_type": "code",
"execution_count": 139,
"id": "516a9c4e",
"metadata": {},
"outputs": [],
"source": [
"def update_inventory(customer_orders,inventory):\n",
" for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product]-=1\n",
" return inventory"
]
},
{
"cell_type": "code",
"execution_count": 140,
"id": "7d9f031e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'t-shirt': 10, 'mug': 17, 'hat': 27, 'book': 37, 'keychain': 50}"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"update_inventory(customer_orders,inventory)"
]
},
{
"cell_type": "code",
"execution_count": 141,
"id": "68b3d978",
"metadata": {},
"outputs": [],
"source": [
"def calculate_order_statistics(customer_orders,products):\n",
" total_products_order=len(customer_orders)\n",
" percentage=(total_products_order / len(products)) * 100\n",
" order_statistics=(total_products_order,percentage)\n",
" return order_statistics"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "abbad890",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3, 60.0)"
]
},
"execution_count": 142,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calculate_order_statistics(customer_orders,products)"
]
},
{
"cell_type": "code",
"execution_count": 143,
"id": "fcca9d9a",
"metadata": {},
"outputs": [],
"source": [
"def print_order_statistics(order_statistics):\n",
" \n",
" print(f\"Total products ordered: {order_statistics[0]}\")\n",
" print(f\"Percentage of unique products ordered: {order_statistics[1]:.2f}%\")"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "f2698e66",
"metadata": {},
"outputs": [],
"source": [
"def print_updated_inventory(inventory):\n",
" for product, qty in inventory.items():\n",
" print(f\"{product}: {qty}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -61,7 +233,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down