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
159 changes: 157 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,166 @@
"\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": [],
"source": [
"productsBV = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"] "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 30, 'mug': 20, 'hat': 23, 'book': 23, 'keychain': 24}\n"
]
}
],
"source": [
"inventoryBV={}\n",
"for pkeys in productsBV:\n",
" inventoryBV[f\"{pkeys}\"]=int(input(f\"enter quantity of product available for {pkeys} in the inventory\"))\n",
" \n",
"print(inventoryBV)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"customer order= {'mug', 'book', 'hat'}\n"
]
}
],
"source": [
"custom_orders=set()\n",
"\n",
"while len(custom_orders)<3:\n",
" custom_orders.add(input(\"enter the name of the product you want to order, between t-shirts, mug, hat, book, keychain\"))\n",
"print(f\"customer order= {custom_orders}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"total_items_ordered=len(custom_orders)\n",
"percentageproductorder=total_items_ordered/sum(inventoryBV.values())*100\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order statistics:\n",
"Total Products Ordered=3\n",
"Percentage of Products Ordered: 2.50\n"
]
}
],
"source": [
"print(f\"\"\"Order statistics:\n",
"Total Products Ordered={total_items_ordered}\n",
"Percentage of Products Ordered: {percentageproductorder:.2f}\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"product=t-shirt, quantity in inventory=30\n",
"product=mug, quantity in inventory=19\n",
"product=hat, quantity in inventory=22\n",
"product=book, quantity in inventory=22\n",
"product=keychain, quantity in inventory=24\n"
]
}
],
"source": [
"\n",
"for orders in custom_orders:\n",
" if orders in inventoryBV:\n",
" inventoryBV[orders]-=1\n",
"\n",
"for keys, values in inventoryBV.items():\n",
" print(f\"product={keys}, quantity in inventory={values}\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 30, 'mug': 19, 'hat': 22, 'book': 22, 'keychain': 24}\n"
]
}
],
"source": [
"print(inventoryBV)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"#THIS END OF LAB 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +223,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down