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
185 changes: 184 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,189 @@
"\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": 47,
"metadata": {},
"outputs": [],
"source": [
"# 1.\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"# 2.\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter quantity: 4\n",
"Enter quantity: 6\n",
"Enter quantity: 7\n",
"Enter quantity: 9\n",
"Enter quantity: 10\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 4, 'mug': 6, 'hat': 7, 'book': 9, 'keychain': 10}\n"
]
}
],
"source": [
"# 3.\n",
"for product in products:\n",
" inventory[product] = int(input(\"Enter quantity: \"))\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"# 4.\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter your order 1: book\n",
"Enter your order 2: mug\n",
"Enter your order 3: hat\n"
]
}
],
"source": [
"# 5.\n",
"for i in range(3):\n",
" order = input(f\"Enter your order {i + 1}: \")\n",
" while order not in products:\n",
" order = input(f\"Enter your order {i + 1}: \")\n",
" customer_orders.add(order) "
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'book', 'hat', 'mug'}"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 6.\n",
"customer_orders"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [],
"source": [
"# 7.\n",
"total_products_ordered = len(customer_orders)\n",
"percentage = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, percentage)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n"
]
}
],
"source": [
"# 8.\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: \", total_products_ordered)\n",
"print(f\"Percentage of Products Ordered: {percentage}%\") \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [],
"source": [
"# 9.\n",
"for product in customer_orders:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 4\n",
"mug: 5\n",
"hat: 6\n",
"book: 8\n",
"keychain: 10\n"
]
}
],
"source": [
"# 10.\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +251,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.0"
}
},
"nbformat": 4,
Expand Down