Skip to content
Open
Show file tree
Hide file tree
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
117 changes: 0 additions & 117 deletions README.md

This file was deleted.

167 changes: 165 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,174 @@
"\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. Create a list containing all available products\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# 2. Create an empty dictionary for the inventory\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# 3. Ask the user for the quantity of each product\n",
"for product in products:\n",
" quantity = int(input(f\"How many {product}s are available? \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# 4. Create an empty set for customer orders\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# 5. Ask the customer to enter three products\n",
"for number in range(3):\n",
" product = input(\n",
" f\"Enter product {number + 1} to order \"\n",
" \"(t-shirt, mug, hat, book, keychain): \"\n",
" ).lower()\n",
"\n",
" customer_orders.add(product)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Products in customer order:\n",
"{'mug', 'hat', 'book'}\n"
]
}
],
"source": [
"# 6. Print the products in the customer order\n",
"print(\"\\nProducts in customer order:\")\n",
"print(customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# 7. Calculate the order statistics\n",
"total_products_ordered = len(customer_orders)\n",
"\n",
"percentage_ordered = (\n",
" total_products_ordered / len(products)\n",
") * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0%\n"
]
}
],
"source": [
"# 8. Print the order statistics\n",
"print(\"\\nOrder Statistics:\")\n",
"print(f\"Total Products Ordered: {order_status[0]}\")\n",
"print(f\"Percentage of Products Ordered: {order_status[1]}%\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# 9. Subtract 1 from the inventory quantity of every product\n",
"for product in products:\n",
" inventory[product] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Updated Inventory:\n",
"t-shirt: 19\n",
"mug: 9\n",
"hat: 9\n",
"book: 49\n",
"keychain: 99\n"
]
}
],
"source": [
"# 10. Print the updated inventory\n",
"print(\"\\nUpdated Inventory:\")\n",
"for product in products:\n",
" print(f\"{product}: {inventory[product]}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +231,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down