Skip to content

lab-python-data-structures #506

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
78 changes: 75 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,85 @@
"\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": 3,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Please enter stock for article t-shirt 1\n",
"Please enter stock for article mug 2\n",
"Please enter stock for article hat 3\n",
"Please enter stock for article book 4\n",
"Please enter stock for article keychain 5\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 1\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 2\n",
"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain 3\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'hat', 'book'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0 %\n",
"The stock for t-shirt is 1\n",
"The stock for mug is 1\n",
"The stock for hat is 2\n",
"The stock for book is 3\n",
"The stock for keychain is 5\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" stock = int(input(f\"Please enter stock for article {product}\"))\n",
" inventory[product] = stock\n",
"\n",
"customer_orders = set()\n",
"\n",
"for purchase in range(3):\n",
" customer_orders.add(products[int(input(\"Please enter 0 for t-shirt, 1 for mug, 2 for hat, 3 for book or 4 for keychain\"))])\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (len(customer_orders)/len(inventory.values()))*100\n",
"\n",
"print(f\"\"\"Order Statistics:\n",
"Total Products Ordered: {total_products_ordered}\n",
"Percentage of Products Ordered: {percentage_ordered} %\"\"\")\n",
"\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"for product in products:\n",
" print(\"The stock for\", product, \"is\", inventory[product])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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 +140,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down