Skip to content

soled lab #511

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
80 changes: 78 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,87 @@
"\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": [
"Enter the quantity for each product:\n",
"Enter 3 products the customer wants to order:\n",
"Customer Ordered Products:\n",
"mug\n",
"book\n",
"hat\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n",
"Updated Inventory:\n",
"t-shirt: 25\n",
"mug: 34\n",
"hat: 44\n",
"book: 54\n",
"keychain: 65\n"
]
}
],
"source": [
"\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"print(\"Enter the quantity for each product:\")\n",
"for item in products:\n",
" quantity = int(input(f\"{item}: \"))\n",
" inventory[item] = quantity \n",
"\n",
"customer_orders = set()\n",
"\n",
"print(\"Enter 3 products the customer wants to order:\")\n",
"for i in range(3):\n",
" product = input(f\"Product {i+1}: \").strip().lower()\n",
" if product in products:\n",
" customer_orders.add(product) \n",
" else:\n",
" print(\"Invalid product. Skipped.\") \n",
"\n",
"print(\"Customer Ordered Products:\")\n",
"for item in customer_orders:\n",
" print(item)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"order_status = (total_products_ordered, round(percentage_ordered, 2)) \n",
"\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n",
"\n",
"for item in customer_orders:\n",
" if inventory[item] > 0:\n",
" inventory[item] -= 1 \n",
"\n",
"print(\"Updated Inventory:\")\n",
"for item in products:\n",
" print(f\"{item}: {inventory[item]}\")\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down