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
220 changes: 219 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,224 @@
"\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": [],
"source": [
"#1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"inventory ={}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Quantify t-shirt product: 5\n",
"Quantify mug product: 4\n",
"Quantify hat product: 7\n",
"Quantify book product: 3\n",
"Quantify keychain product: 2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 5, 'mug': 4, 'hat': 7, 'book': 3, 'keychain': 2}\n"
]
}
],
"source": [
"#3 \n",
"inventory = {\"t-shirt\": 0,\n",
" \"mug\": 0,\n",
" \"hat\": 0,\n",
" \"book\": 0,\n",
" \"keychain\": 0}\n",
"inventory[\"t-shirt\"] = int(input(\"Quantify t-shirt product: \"))\n",
"inventory[\"mug\"] = int(input(\"Quantify mug product: \"))\n",
"inventory[\"hat\"] = int(input(\"Quantify hat product: \"))\n",
"inventory[\"book\"] = int(input(\"Quantify book product: \"))\n",
"inventory[\"keychain\"] = int(input(\"Quantify keychain product: \"))\n",
"\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"#4\n",
"costumer_orders = {}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Add first product: hat\n",
"Add second product: t-shirt\n",
"Add third product: mug\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"['hat', 't-shirt', 'mug']\n"
]
}
],
"source": [
"#5 and 6\n",
"\n",
"customer_orders = []\n",
"\n",
"customer_orders.append(input(\"Add first product: \").lower())\n",
"customer_orders.append(input(\"Add second product: \").lower())\n",
"customer_orders.append(input(\"Add third product: \").lower())\n",
"\n",
"print(customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Add first product: mug\n",
"Add second product: t-shirt\n",
"Add third product: hat\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer orders: {'hat', 't-shirt', 'mug'}\n",
"Order status: (3, 60.0)\n"
]
}
],
"source": [
"#7\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"customer_orders = set()\n",
"\n",
"customer_orders.add(input(\"Add first product: \").lower())\n",
"customer_orders.add(input(\"Add second product: \").lower())\n",
"customer_orders.add(input(\"Add third product: \").lower())\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_of_products_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_of_products_ordered)\n",
"\n",
"print(\"Customer orders:\", customer_orders)\n",
"print(\"Order status:\", order_status)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n"
]
}
],
"source": [
"#8\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"#9\n",
"\n",
"inventory[\"t-shirt\"] -= (\"t-shirt\" in customer_orders)\n",
"inventory[\"mug\"] -= (\"mug\" in customer_orders)\n",
"inventory[\"hat\"] -= (\"hat\" in customer_orders)\n",
"inventory[\"book\"] -= (\"book\" in customer_orders)\n",
"inventory[\"keychain\"] -= (\"keychain\" in customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory:\n",
"t-shirt: 4\n",
"mug: 3\n",
"hat: 6\n",
"book: 3\n",
"keychain: 2\n"
]
}
],
"source": [
"#10\n",
"\n",
"print(\"Updated Inventory:\")\n",
"print(f\"t-shirt: {inventory['t-shirt']}\")\n",
"print(f\"mug: {inventory['mug']}\")\n",
"print(f\"hat: {inventory['hat']}\")\n",
"print(f\"book: {inventory['book']}\")\n",
"print(f\"keychain: {inventory['keychain']}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +286,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down