Skip to content

Added solution #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
170 changes: 167 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,177 @@
"\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": 5,
"metadata": {},
"outputs": [],
"source": [
"#1.\n",
"products=[\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] #products list"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"#2.\n",
"inventory={} #empty dictionary"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the number of available t-shirt 5\n",
"Enter the number of available mug 9\n",
"Enter the number of available hat 5\n",
"Enter the number of available book 45\n",
"Enter the number of available keychain 58\n"
]
}
],
"source": [
"#3.\n",
"for product in products:\n",
" inventory[product]=input(f\"Enter the number of available {product}\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#4.\n",
"customer_orders=set() #set"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter any product that a customer wants to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
"Enter any product that a customer wants to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n",
"Enter any product that a customer wants to order from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] keychain\n"
]
}
],
"source": [
"#5.\n",
"for i in range(3):\n",
" customer_orders.add(input(f\"Enter any product that a customer wants to order from {products} \"))\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'book', 'mug', 'keychain'}\n"
]
}
],
"source": [
"#6.\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#7.\n",
"total_products_ordered=len(customer_orders)\n",
"percentage_ordered =100*total_products_ordered/len(products)\n",
"order_status=(total_products_ordered,percentage_ordered)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"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",
"\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}% \")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"#9.\n",
"for customer_order in customer_orders:\n",
" if customer_order in inventory and int(inventory[customer_order])>0:\n",
" inventory[customer_order]=str(int(inventory[customer_order])-1)\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt-5\n",
"mug-8\n",
"hat-5\n",
"book-44\n",
"keychain-57\n"
]
}
],
"source": [
"#10.\n",
"for key,value in inventory.items():\n",
" print(f\"{key}-{value}\")\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -68,7 +232,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down