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
110 changes: 107 additions & 3 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,117 @@
"\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": 55,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter quantity for t-shirt 4\n",
"Enter quantity for mug 5\n",
"Enter quantity for hat 3\n",
"Enter quantity for book 6\n",
"Enter quantity for keychain 7\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 4, 'mug': 5, 'hat': 3, 'book': 6, 'keychain': 7}\n"
]
},
{
"name": "stdin",
"output_type": "stream",
"text": [
"Choose one item from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] tshirt\n",
"Choose one item from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] mug\n",
"Choose one item from ['t-shirt', 'mug', 'hat', 'book', 'keychain'] hat\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'tshirt', 'mug', 'hat'}\n",
"60.0\n",
"(3, 60.0)\n",
"Order statistics:\n",
"total products ordered: 3 \n",
"percentage ordered: 60.0%\n",
"Updated Inventory:\n",
"t-shirt: 3\n",
"mug: 4\n",
"hat: 2\n",
"book: 5\n",
"keychain: 6\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"inventory = {}\n",
"\n",
"for i in products: \n",
" quantity = int(input(f\"Enter quantity for {i}\"))\n",
" inventory[i] = quantity\n",
"\n",
"print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"for i in range(3):\n",
" order = input(f\"Choose one item from {products}\")\n",
" customer_orders.add(order)\n",
"print(customer_orders)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"\n",
"percentage_ordered = (total_products_ordered/len(products))* 100\n",
"\n",
"print(percentage_ordered)\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"print(order_status)\n",
"\n",
"print(f\"Order statistics:\")\n",
"print(f\"total products ordered: {order_status[0]} \")\n",
"print(f\"percentage ordered: {order_status[1]}%\")\n",
"\n",
"\n",
"inventory[\"t-shirt\"] = inventory[\"t-shirt\"] - 1\n",
"inventory[\"mug\"] = inventory[\"mug\"] - 1\n",
"inventory[\"hat\"] = inventory[\"hat\"] - 1\n",
"inventory[\"book\"] = inventory[\"book\"] - 1\n",
"inventory[\"keychain\"] = inventory[\"keychain\"] - 1\n",
"\n",
"print(\"Updated Inventory:\")\n",
"print(\"t-shirt:\", inventory[\"t-shirt\"])\n",
"print(\"mug:\", inventory[\"mug\"])\n",
"print(\"hat:\", inventory[\"hat\"])\n",
"print(\"book:\", inventory[\"book\"])\n",
"print(\"keychain:\", inventory[\"keychain\"])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:base] *",
"language": "python",
"name": "python3"
"name": "conda-base-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -68,7 +172,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down