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
260 changes: 259 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,264 @@
"\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": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"
]
}
],
"source": [
"print(products)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of t-shirt: 23\n",
"Enter the quantity of mug: 17\n",
"Enter the quantity of hat: 9\n",
"Enter the quantity of book: 4\n",
"Enter the quantity of keychain: 15\n"
]
}
],
"source": [
"for product in products:\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 23, 'mug': 17, 'hat': 9, 'book': 4, 'keychain': 15}\n"
]
}
],
"source": [
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a product to order: mug\n",
"Enter a product to order: book\n",
"Enter a product to order: hat\n"
]
}
],
"source": [
"for i in range(3):\n",
" product_order = input(\"Enter a product to order: \")\n",
" customer_orders.add(product_order)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'hat', 'book'}\n"
]
}
],
"source": [
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"total_products_ordered = len(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"print (len(customer_orders))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(products)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"percentage_ordered = (total_products_ordered / len(products)) * 100"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"order_status = (total_products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3, 60.0)\n"
]
}
],
"source": [
"print(order_status)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n"
]
}
],
"source": [
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", total_products_ordered)\n",
"print(\"Percentage of Products Ordered:\", percentage_ordered, \"%\")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" inventory[product] = inventory[product] - 1"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 23, 'mug': 16, 'hat': 8, 'book': 3, 'keychain': 15}\n"
]
}
],
"source": [
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down