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
75 changes: 73 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,82 @@
"\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": 98,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer Orders: {'mug', 't-shirt', 'hat'}\n",
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"\n",
"Updated Inventory:\n",
"t-shirt: 9\n",
"mug: 7\n",
"hat: 5\n",
"book: 11\n",
"keychain: 3\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"# Input inventory with validation\n",
"for product in products:\n",
" while True:\n",
" try:\n",
" quantity = int(input(f\"Enter quantity for {product}: \"))\n",
" inventory[product] = quantity\n",
" break\n",
" except:\n",
" print(\"Please enter a valid number\")\n",
"\n",
"customer_orders = set()\n",
"\n",
"# Input orders with validation\n",
"for i in range(3):\n",
" while True:\n",
" order = input(\"Enter a product to order: \")\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" break\n",
" else:\n",
" print(\"Invalid product, try again\")\n",
"\n",
"print(\"Customer Orders:\", customer_orders)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"# Clear inventory update\n",
"for product in products:\n",
" inventory[product] -= 1\n",
"\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +139,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down