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
Binary file added .DS_Store
Binary file not shown.
176 changes: 175 additions & 1 deletion lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,180 @@
"\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": 61,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"inventory[products[0]] = int(input(f\"Give me the quantity of {products[0]}: \"))\n",
"inventory[products[1]] = int(input(f\"Give me the quantity of {products[1]}: \"))\n",
"inventory[products[2]] = int(input(f\"Give me the quantity of {products[2]}: \"))\n",
"inventory[products[3]] = int(input(f\"Give me the quantity of {products[3]}: \"))\n",
"inventory[products[4]] = int(input(f\"Give me the quantity of {products[4]}: \"))"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 2, 'mug': 3, 'hat': 4, 'book': 1, 'keychain': 5}\n"
]
}
],
"source": [
"print(inventory)"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'mug', 'hat', 'book'}\n"
]
}
],
"source": [
"product1 = input(f\"Give me the name of a product you want to oredered it. Choose one of this list {products}\")\n",
"product2 = input(f\"Give me the name of a product you want to oredered it. Choose one of this list {products}\")\n",
"product3 = input(f\"Give me the name of a product you want to oredered it. Choose one of this list {products}\")\n",
"\n",
"customer_orders.add(product1)\n",
"customer_orders.add(product2)\n",
"customer_orders.add(product3)\n",
"\n",
"print(customer_orders)\n"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"num_products = len(customer_orders)\n",
"percentage = num_products/len(products)*100\n",
"\n",
"order_status = (num_products,percentage)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Order Statistics:\n",
" Total Products Ordered: 3\n",
" Percentage of Products Ordered: 60.0 \n",
" \n"
]
}
],
"source": [
"print(f'''\n",
" Order Statistics:\n",
" Total Products Ordered: {num_products}\n",
" Percentage of Products Ordered: {percentage} \n",
" ''')"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"for product in customer_orders:\n",
" if inventory[product] > 0:\n",
" inventory[product] -= 1\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" Updated inventory: \n",
"\n",
" t-shirt: 2 \n",
"\n",
" mug: 2 \n",
"\n",
" hat: 3 \n",
"\n",
" book: 0 \n",
"\n",
" keychain: 5 \n",
"\n",
" \n"
]
}
],
"source": [
"print(f''' Updated inventory: \\n\n",
" {products[0]}: {inventory[products[0]]} \\n\n",
" {products[1]}: {inventory[products[1]]} \\n\n",
" {products[2]}: {inventory[products[2]]} \\n\n",
" {products[3]}: {inventory[products[3]]} \\n\n",
" {products[4]}: {inventory[products[4]]} \\n\n",
" ''' )\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -68,7 +242,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down