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
82 changes: 71 additions & 11 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"# Lab | Data Structures "
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -50,11 +41,80 @@
"\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": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inventory: {'t-shirt': 19, 'mug': 20, 'hat': 18, 'book': 5, 'keychain': 4}\n",
"Customer Orders: {' book', 'mug', ' hat'}\n",
"Order Statistics:\n",
"Total products ordered: 3\n",
"Percentage of products ordered: 4.55%\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"quantity_tshirt = int(input(\"Enter the quantity for t-shirt: \"))\n",
"quantity_mug = int(input(\"Enter the quantity for mug: \"))\n",
"quantity_hat = int(input(\"Enter the quantity for hat: \"))\n",
"quantity_book = int(input(\"Enter the quantity for book: \"))\n",
"quantity_keychain = int(input(\"Enter the quantity for keychain: \"))\n",
"inventory[\"t-shirt\"] = quantity_tshirt\n",
"inventory[\"mug\"] = quantity_mug\n",
"inventory[\"hat\"] = quantity_hat\n",
"inventory[\"book\"] = quantity_book\n",
"inventory[\"keychain\"] = quantity_keychain\n",
"print(f\"Inventory: {inventory}\")\n",
"customer_orders = set()\n",
"customer_wants_to_order = input(\"Enter the 3 products you want to order from the list (separated by commas): \")\n",
"customer_wants_to_order_list = customer_wants_to_order.split(\",\")\n",
"customer_orders.update(customer_wants_to_order_list)\n",
"print(f\"Customer Orders: {customer_orders}\")\n",
"total_products_ordered = len(customer_orders)\n",
"total_products_available = sum(inventory.values())\n",
"order_percentage = (total_products_ordered/total_products_available) * 100\n",
"order_status = (total_products_ordered, order_percentage)\n",
"print(\"Order Statistics:\")\n",
"print(f\"Total products ordered: {order_status[0]}\")\n",
"print(f\"Percentage of products ordered: {order_status[1]:.2f}%\")\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total stock after the order for book: 18\n",
"Total stock after the order for hat: 14\n",
"Total stock after the order for mug: 17\n"
]
}
],
"source": [
"inventory[\"book\"] = inventory[\"book\"] - 1\n",
"inventory[\"hat\"] = inventory[\"hat\"] - 1\n",
"inventory[\"mug\"] = inventory[\"mug\"] - 1\n",
"print(f\"Total stock after the order for book: {inventory['book']}\")\n",
"print(f\"Total stock after the order for hat: {inventory['hat']}\")\n",
"print(f\"Total stock after the order for mug: {inventory['mug']}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +128,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down