Skip to content
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

lab data structures solved #422

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
72 changes: 70 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,79 @@
"\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": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']\n",
"{'t-shirt': 5, 'mug': 6, 'hat': 4, 'book': 2, 'keychain': 8}\n",
"{'book', 'hat', 'mug'}\n",
"Order Statistics:\n",
"Total number of orders: 3\n",
"The percentage of ordered products to available products is 60.0%: \n",
"(3, 60.0)\n",
"('t-shirt', 4)\n",
"('mug', 5)\n",
"('hat', 3)\n",
"('book', 1)\n",
"('keychain', 7)\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(f\"Please add the amount for {product} to the stock\"))\n",
" inventory[product] = quantity\n",
"\n",
"\n",
"print(products)\n",
"print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"for i in range(3):\n",
" product = input(f\"Enter the name of a product from the list {products}: \")\n",
" if product in products:\n",
" customer_orders.add(product)\n",
" products.remove(product)\n",
" else:\n",
" print(f\"{product} is not in the list of available products. Please try again.\")\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_orders = len(customer_orders)\n",
"\n",
"ratio = (len(customer_orders) / len(inventory))*100\n",
"\n",
"order_status = (total_orders, ratio)\n",
"\n",
"print(\"Order Statistics:\")\n",
"print(\"Total number of orders:\", total_orders)\n",
"print(f\"The percentage of ordered products to available products is {ratio}%: \")\n",
"print(order_status)\n",
"\n",
"for product in inventory:\n",
" inventory[product] -= 1\n",
"\n",
"\n",
"for products in inventory.items():\n",
" print(products)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +136,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down