Skip to content

lab complete #502

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
77 changes: 76 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,81 @@
"\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": 22,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter the quantity of t-shirt: 1\n",
"Enter the quantity of mug: 2\n",
"Enter the quantity of hat: 3\n",
"Enter the quantity of book: 4\n",
"Enter the quantity of keychain: 5\n",
"Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
"Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n",
"Enter one of these products : ['t-shirt', 'mug', 'hat', 'book', 'keychain'] book\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"This is the customer order : {'mug', 'hat', 'book'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3.\n",
"Percentage of Products Ordered: 20.00%. \n",
"This is the inventory after customer order :\n",
"t-shirt : 1\n",
"mug : 1\n",
"hat : 2\n",
"book : 3\n",
"keychain : 5\n"
]
}
],
"source": [
"list_products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"customer_orders = set()\n",
"\n",
"for product in list_products :\n",
" quantity = int(input(f\"Enter the quantity of {product}: \"))\n",
" inventory[product] = quantity\n",
" \n",
"for order in range (3):\n",
" customer_orders.add(input(f\"Enter one of these products : {list_products}\"))\n",
" \n",
"total_prod_ordered = len(customer_orders)\n",
"total_inventory = sum(inventory.values()) \n",
"percentage_products_ordered = (total_prod_ordered / total_inventory)*100\n",
"order_status = (total_prod_ordered, percentage_products_ordered) \n",
"\n",
"for product in customer_orders :\n",
" if product in inventory and inventory[product] > 0:\n",
" inventory[product] -= 1\n",
" \n",
"\n",
"print(f\"This is the customer order : {customer_orders}\")\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}.\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]:.2f}%. \")\n",
"\n",
"print(f\"This is the inventory after customer order :\")\n",
"for product, quantity in inventory.items():\n",
" print (f\"{product} : {quantity}\") \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down