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
224 changes: 223 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,228 @@
"\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": [
"#1\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"#2\n",
"inventory={}"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"quantity of t-shirt: 5\n",
"quantity of mug: 4\n",
"quantity of hat: 3\n",
"quantity of book: 2\n",
"quantity of keychain: 1\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 4, 'hat': 3, 'book': 2, 'keychain': 1}\n"
]
}
],
"source": [
"#3\n",
"for product in products:\n",
" quantity=int(input(f\"quantity of {product}:\"))\n",
" inventory[product]=quantity\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#4\n",
"customer_orders=set()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: book\n",
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: hat\n",
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: sh\n",
"product not available or already selected, please select a product out of ['t-shirt', 'mug', 'hat', 'book', 'keychain']: book\n",
"available products are ['t-shirt', 'mug', 'hat', 'book', 'keychain']: keychain\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'hat', 'keychain'}\n"
]
}
],
"source": [
"#5\n",
"customer_orders.clear()\n",
"while len(customer_orders)<3:\n",
" customer_product=input(f\"available products are {products}:\")\n",
" if customer_product not in products or customer_product in customer_orders:\n",
" customer_product2=input(f\"product not available or already selected, please select a product out of {products}:\")\n",
" if customer_product2 in products and customer_product2 not in customer_orders:\n",
" customer_orders.add(customer_product2)\n",
" else:\n",
" customer_orders.add(customer_product)\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'hat', 'keychain'}\n"
]
}
],
"source": [
"#6\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(3, '60%')\n"
]
}
],
"source": [
"#7\n",
"#Total Products Ordered: The total number of products in the customer_orders set.\n",
"number_orders=len(customer_orders)\n",
"ordered_products=f\"{int((number_orders/len(products))*100)}%\"\n",
"order_status=(number_orders, ordered_products)\n",
"print(order_status)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60%\n"
]
}
],
"source": [
"#8\n",
"print(f\"Order Statistics:\\nTotal Products Ordered: {number_orders}\\nPercentage of Products Ordered: {ordered_products}\")"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 4, 'hat': 3, 'book': 2, 'keychain': 1}\n"
]
}
],
"source": [
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 81,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 0}\n"
]
}
],
"source": [
"#9\n",
"for order in customer_orders:\n",
" inventory[order]=inventory[order]-1\n",
"#print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 4, 'hat': 2, 'book': 1, 'keychain': 0}\n"
]
}
],
"source": [
"#10\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +290,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down