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
157 changes: 155 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,164 @@
"\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": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['t-shirt', 'mug', 'hat', 'book', 'keychain']\n"
]
}
],
"source": [
"# Step 1: Define the products list\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"print(products)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 2, 'mug': 4, 'hat': 3, 'book': 5, 'keychain': 1}\n"
]
}
],
"source": [
"quantity0 = int(input(f\"Enter the quantity for {products[0]}: \"))\n",
"inventory[products[0]] = quantity0\n",
"quantity1 = int(input(f\"Enter the quantity for {products[1]}: \"))\n",
"inventory[products[1]] = quantity1\n",
"quantity2 = int(input(f\"Enter the quantity for {products[2]}: \"))\n",
"inventory[products[2]] = quantity2\n",
"quantity3 = int(input(f\"Enter the quantity for {products[3]}: \"))\n",
"inventory[products[3]] = quantity3\n",
"quantity4 = int(input(f\"Enter the quantity for {products[4]}: \"))\n",
"inventory[products[4]] = quantity4\n",
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"customers_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"product1 = input(f\"Enter a name for the first product from {products}: \")\n",
"customers_orders.add(product1)\n",
"product2 = input(f\"Enter a name for the second product from {products}: \")\n",
"customers_orders.add(product2)\n",
"product3 = input(f\"Enter a name for the third product from {products}: \")\n",
"customers_orders.add(product3)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt', 'book', 'hat'}\n"
]
}
],
"source": [
"print(customers_orders)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total products ordered: 3\n",
"Percentage of products ordered: 60.00%\n",
"(3, 60.0)\n"
]
}
],
"source": [
"total_products_ordered = len(customers_orders)\n",
"print(f\"Total products ordered: {total_products_ordered}\")\n",
"\n",
"percentage_orders = (total_products_ordered / len(products)) * 100\n",
"print(f\"Percentage of products ordered: {percentage_orders:.2f}%\")\n",
"\n",
"order_status = (total_products_ordered, percentage_orders)\n",
"print(order_status)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Inventory after updating for customer orders:\n",
"T-shirt: 1\n",
"Mug: 4\n",
"Hat: 2\n",
"Book: 4\n",
"Keychain: 1\n"
]
}
],
"source": [
"inventory[products[0]] -= 1\n",
"inventory[products[2]] -= 1\n",
"inventory[products[3]] -= 1\n",
"\n",
"print(\"\\nInventory after updating for customer orders:\")\n",
"print(f\"T-shirt: {inventory[products[0]]}\")\n",
"print(f\"Mug: {inventory[products[1]]}\")\n",
"print(f\"Hat: {inventory[products[2]]}\")\n",
"print(f\"Book: {inventory[products[3]]}\")\n",
"print(f\"Keychain: {inventory[products[4]]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +221,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.3"
}
},
"nbformat": 4,
Expand Down