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
124 changes: 122 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,131 @@
"\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": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Final inventory {'t-shirts': 20, 'mug': 15, 'hat': 20, 'book': 10, 'keychain': 15}\n"
]
}
],
"source": [
"products = [\"t-shirts\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for item in products:\n",
" quantity = int(input(f\"Please enter the quantity for {item}: \"))\n",
" inventory[item] = quantity\n",
"\n",
"print(\"Final inventory\", inventory)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer orders {'hat', 'book', 'mug'}\n"
]
}
],
"source": [
"customers_orders = set()\n",
"\n",
"for products in range(3):\n",
" order = input(\"Please enter the product they ordered:\")\n",
" customers_orders.add(order)\n",
"\n",
"print(\"Customer orders\", customers_orders)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total products ordered: 3\n"
]
}
],
"source": [
"total_orders = len(customers_orders)\n",
"print(\"Total products ordered:\", total_orders)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order statistics:\n",
"Total products 5\n",
"customer ordered 60.0% of available products.\n"
]
}
],
"source": [
"total_available_products = len(inventory.values())\n",
"percentage_ordered = (total_orders / total_available_products) * 100\n",
"\n",
"order_status = (total_orders, percentage_ordered)\n",
"\n",
"print(\"Order statistics:\")\n",
"print(\"Total products\", total_available_products) \n",
"print(f\"customer ordered {percentage_ordered}% of available products.\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated inventory after selling one unit of each ordered product:\n",
"t-shirts: 20\n",
"mug: 14\n",
"hat: 19\n",
"book: 9\n",
"keychain: 15\n"
]
}
],
"source": [
"for product in customers_orders:\n",
" inventory[product] -= 1\n",
"\n",
"print(\"Updated inventory after selling one unit of each ordered product:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +188,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down