Skip to content
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
75 changes: 73 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,82 @@
"\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": [
"Inventory:\n",
"t-shirt: 5\n",
"mug: 4\n",
"hat: 8\n",
"book: 73\n",
"keychain: 5\n",
"Customer orders: {'book', 'mug', 'hat'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 3.1578947368421053 %\n",
"Inventory apdeted:\n",
"t-shirt: 4\n",
"mug: 3\n",
"hat: 7\n",
"book: 72\n",
"keychain: 4\n"
]
}
],
"source": [
"products = [ \"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"for product in products:\n",
" pr_q = int(input(f\"Please enter the quantity of a product avalible: {product}\"))\n",
" inventory[product] = pr_q\n",
"\n",
"print(\"Inventory:\")\n",
"\n",
"for product, pr_q in inventory.items():\n",
" print (f\"{product}: {pr_q}\")\n",
"\n",
"customer_orders = set()\n",
"for _ in range(3):\n",
" while True:\n",
" pr = (input(f\"Please enter the name of the product from the list that you want to order : {products}\"))\n",
" \n",
" if pr in products:\n",
" customer_orders.add(pr)\n",
" break\n",
" else:\n",
" print(\"This product is not available. Please choose from the list.\")\n",
"\n",
"print(f\"Customer orders: {customer_orders}\")\n",
"\n",
"tpo = int(len(customer_orders))\n",
"sum_inv = int(sum(inventory.values()))\n",
"ppo = (tpo/sum_inv)*100\n",
"order_status = (tpo, ppo)\n",
"\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {tpo}\")\n",
"print(f\"Percentage of Products Ordered: {ppo} %\")\n",
"\n",
"for key in inventory:\n",
" inventory[key] -=1\n",
" \n",
"print(\"Inventory apdeted:\")\n",
"\n",
"for product, pr_q in inventory.items():\n",
" print (f\"{product}: {pr_q}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +139,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down