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
275 changes: 273 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,282 @@
"\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": 3,
"metadata": {},
"outputs": [],
"source": [
"Products = [\"t-shirt\", \"mug\", \"hat\", \"book\",\"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"Inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"Inventory[\"T-shirt\"] = input(\"Add the inventory for t-shirt items, please: \")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"Inventory[\"Mug\"] = input(\"Add the inventory for mug itmes, please: \")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"Inventory[\"Hat\"] = input(\"Add the inventory for hat itmes, please: \")"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"Inventory[\"Book\"] = input(\"Add the inventory for book itmes, please: \")"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"Inventory[\"Keychain\"] = input(\"Add the inventory for keychain itmes, please: \")"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [],
"source": [
"for i in range(3):\n",
" choice =input(f\"Write the name of the product {i+1}: \")"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You choose: Book\n",
"\n",
"Final order: {'Book'}\n"
]
}
],
"source": [
"customer_orders.add( choice)\n",
"print(f\"You choose: {choice}\")\n",
"print(\"\\nFinal order:\", customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Your order:\n",
" Book\n"
]
}
],
"source": [
"print(\"\\nYour order:\")\n",
"for products in customer_orders:\n",
" print(f\" {products}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total number of product orders: 1\n"
]
}
],
"source": [
"total_products = len(customer_orders)\n",
"print(f\"total number of product orders: {total_products}\")"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
"total_inventory = 5"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"total_orders = len(customer_orders)\n",
"percentage = (total_orders / total_inventory)* 100"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"order_status = (total_orders, percentage)"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"total orders: 1\n",
"inventory percentage: 20.0%\n"
]
}
],
"source": [
"print(f\"total orders: {order_status[0]}\")\n",
"print(f\"inventory percentage: {order_status[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Order Statistics\n",
"Total Products Ordered: 1\n",
"Percentage of Products Ordered: 20.0%\n"
]
}
],
"source": [
"print(\"\\nOrder Statistics\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [],
"source": [
"inventory = {\n",
" \"t-shirt\": 10,\n",
" \"hat\": 5,\n",
" \"book\": 8,\n",
" \"mug\": 12\n",
"} "
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Product Book not found in inventory.\n"
]
}
],
"source": [
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
" print(f\"Inventory updated: {product} now has {inventory[product]} units.\")\n",
" else:\n",
" print(f\"Product {product} not found in inventory.\")\n"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"--- Updated Inventory ---\n",
"Product: t-shirt | Remaining: 10\n",
"Product: hat | Remaining: 5\n",
"Product: book | Remaining: 8\n",
"Product: mug | Remaining: 12\n"
]
}
],
"source": [
"print(\"\\n--- Updated Inventory ---\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"Product: {product} | Remaining: {quantity}\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +339,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down