Skip to content

Lab solved #504

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
168 changes: 167 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,172 @@
"\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": 53,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"t-shirt quantities: 400\n",
"mug quantities: 500\n",
"hat quantities: 700\n",
"book quantities: 1000\n",
"keychain quantities: 200\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"input0= int(input(\"t-shirt quantities:\"))\n",
"input1= int(input(\"mug quantities:\"))\n",
"input2= int(input(\"hat quantities:\"))\n",
"input3= int(input(\"book quantities:\"))\n",
"input4= int(input(\"keychain quantities:\"))\n",
"\n",
"inventory = {\n",
" products[0]:input0,\n",
" products[1]:input1, \n",
" products[2]:input2, \n",
" products[3]:input3, \n",
" products[4]:input4\n",
"}\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"ordered product: book\n",
"ordered product: piyya\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Item is not in the list\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"ordered product: hat\n",
"ordered product: mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer order:{'mug', 'hat', 'book'}\n"
]
}
],
"source": [
"customer_orders = set()\n",
"\n",
"while len(customer_orders)<=2:\n",
" order = input(\"ordered product:\")\n",
" for item in order:\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" else:\n",
" print(\"Item is not in the list\")\n",
" break\n",
"print(f\"Customer order:{customer_orders}\") "
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3\n",
"Percentage of Products Ordered:60.0%\n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = len(customer_orders)*100/len(products)\n",
"order_status=(total_products_ordered, percentage_ordered)\n",
"\n",
"print(f\"Total Products Ordered: {total_products_ordered}\")\n",
"print(f\"Percentage of Products Ordered:{percentage_ordered}%\")"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total Products Ordered: 3\n",
"Percentage of Products Ordered:60.0%\n"
]
}
],
"source": [
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = len(customer_orders)*100/len(products)\n",
"order_status=(total_products_ordered, percentage_ordered)\n",
"\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered:{order_status[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory:\n",
"t-shirt: 400\n",
"mug: 499\n",
"hat: 699\n",
"book: 999\n",
"keychain: 200\n"
]
}
],
"source": [
"for product in customer_orders:\n",
" if product in inventory:\n",
" inventory[product] -= 1\n",
"print(\"Updated Inventory:\")\n",
"for product, quantity in inventory.items():\n",
" print(f\"{product}: {quantity}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +234,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down