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
103 changes: 101 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,110 @@
"\n",
"Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10, 'mug': 10, 'hat': 10, 'book': 10, 'keychain': 10}\n",
"{'book', 'hat', 'mug'}\n",
"The number of orders is 3\n",
"The percentage is 60.0 %\n",
"(3, 60.0)\n",
"Order Statistics: \n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60 %\n",
"Updated Inventory :\n",
"Inventory of t-shirts : 10\n",
"Inventory of mugs : 9\n",
"Inventory of hats : 9\n",
"Inventory of books : 9\n",
"Inventory of keychains : 10\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(\"enter quantity of stock of \"))\n",
" inventory[product] = quantity\n",
"\n",
"print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"order = input(\"add 3 products to your order\")\n",
"customer_orders.add(order)\n",
"\n",
"order = input(\"add 2 products to your order\")\n",
"customer_orders.add(order)\n",
"\n",
"order = input(\"add 3 products to your order\")\n",
"customer_orders.add(order)\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_orders = len(customer_orders)\n",
"total_products = len(products)\n",
"\n",
"print(\"The number of orders is \", total_orders)\n",
"\n",
"percentage_products = ((total_orders / total_products) * 100)\n",
"\n",
"print(\"The percentage is \", percentage_products,\"%\")\n",
"\n",
"order_status = (total_orders, percentage_products)\n",
"\n",
"print(order_status)\n",
"\n",
"# 8\n",
"\n",
"print(\"Order Statistics: \")\n",
"print(\"Total Products Ordered: \", total_orders)\n",
"print(\"Percentage of Products Ordered: \", int(percentage_products), \"%\")\n",
"\n",
"\n",
"# 9\n",
"\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -=1\n",
"\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -=1\n",
"\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -=1\n",
"\n",
"\n",
"#10\n",
"\n",
"print(\"Updated Inventory :\")\n",
"print(\"Inventory of t-shirts :\", inventory[\"t-shirt\"])\n",
"print(\"Inventory of mugs :\", inventory[\"mug\"])\n",
"print(\"Inventory of hats :\", inventory[\"hat\"])\n",
"print(\"Inventory of books :\", inventory[\"book\"])\n",
"print(\"Inventory of keychains :\", inventory[\"keychain\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +167,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down