Skip to content

fixed pull request #533

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 2 commits 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
107 changes: 105 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"# Lab | Data Structures "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -50,11 +55,109 @@
"\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": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 10}\n",
"{'t-shirt': 10, 'mug': 20}\n",
"{'t-shirt': 10, 'mug': 20, 'hat': 30}\n",
"{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40}\n",
"{'t-shirt': 10, 'mug': 20, 'hat': 30, 'book': 40, 'keychain': 50}\n",
"products in customer orders: {'hat', 'mug', 'book'}\n",
"order statistics:\n",
"total products ordered: 3\n",
"percentage of unique products ordered : 60.0%\n"
]
}
],
"source": [
"#1.\n",
"\n",
"products = [\"t-shirt\",\"mug\",\"hat\",\"book\",\"keychain\"]\n",
"\n",
"#2.\n",
"\n",
"inventory = {}\n",
"\n",
"#3.\n",
"for product in products:\n",
" quantity = int(input(f\"how many {product} available?\"))\n",
" inventory[product] = quantity\n",
" print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"product_name = input(\"Enter the name of a product that a customer wants:\")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product that a customer wants:\")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product that a customer wants:\")\n",
"customer_orders.add(product_name)\n",
"\n",
"#6\n",
"print(f\"products in customer orders: {customer_orders}\")\n",
"\n",
"#7\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered/len(products))* 100\n",
"order_stats= (total_products_ordered, percentage_ordered)\n",
"\n",
"#8.\n",
"\n",
"print(\"order statistics:\")\n",
"print(\"total products ordered: \", order_stats[0])\n",
"print(f\"percentage of unique products ordered : {order_stats[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"#9\n",
"\n",
"for product in products:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t-shirt: 6\n",
"mug: 16\n",
"hat: 26\n",
"book: 36\n",
"keychain: 46\n"
]
}
],
"source": [
"#10\n",
"\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down