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
87 changes: 85 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,94 @@
"\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": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Products in customer order: {'book', 'mug', 'hat'}\n",
"Order Statistics\n",
"Total Products ordered: 3\n",
"Percentage of Products ordered: 60.0 %\n",
"Updated_Inventory: \n",
"T-shirt 5\n",
"Mug 1\n",
"Hat 5\n",
"Book 3\n",
"Keychain 2\n"
]
}
],
"source": [
"#1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#2 \n",
"inventory = {}\n",
"#3\n",
"quantity = int(input(\"Please enter the quantity of t-shirt in inventory: \"))\n",
"inventory[\"t-shirt\"] = quantity\n",
"\n",
"quantity = int(input(\"Please enter the quantity of mug in inventory: \"))\n",
"inventory[\"mug\"] = quantity\n",
"\n",
"quantity = int(input(\"Please enter the quantity of hat in inventory: \"))\n",
"inventory[\"hat\"] = quantity\n",
"\n",
"quantity = int(input(\"Please enter the quantity of book in inventory: \"))\n",
"inventory[\"book\"] = quantity\n",
"\n",
"quantity = int(input(\"Please enter the quantity of keychain in inventory: \"))\n",
"inventory[\"keychain\"] = quantity\n",
"\n",
"#4\n",
"customer_orders = set()\n",
"\n",
"#5\n",
"product_name = input(\"Please enter the product name the customer wants to order: \").lower()\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Please enter the product name the customer wants to order: \").lower()\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Please enter the product name the customer wants to order: \").lower()\n",
"customer_orders.add(product_name)\n",
"\n",
"#6\n",
"print(\"Products in customer order: \", customer_orders)\n",
"\n",
"#7\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = total_products_ordered/len(products) * 100 \n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"#8\n",
"print(\"Order Statistics\")\n",
"print(\"Total Products ordered: \", order_status[0])\n",
"print(\"Percentage of Products ordered: \", order_status[1],\"%\")\n",
"\n",
"#9\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -= 1\n",
"\n",
"#10\n",
"print(\"Updated_Inventory: \")\n",
"print(\"T-shirt\", inventory[\"t-shirt\"])\n",
"print(\"Mug\", inventory[\"mug\"])\n",
"print(\"Hat\", inventory[\"hat\"])\n",
"print(\"Book\", inventory[\"book\"])\n",
"print(\"Keychain\", inventory[\"keychain\"])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +151,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down