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
174 changes: 172 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,181 @@
"\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": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"30\n",
" Customer ordered 3 products\n",
" Customer order made up 60.0 percentage of the total avalable orders\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.00%\n",
"Updated Inventory\n",
"T-shirt : 5\n",
"Mug : 4\n",
"Hat : 4\n",
"Book : 5\n",
"Keychain : 4\n"
]
}
],
"source": [
"\n",
"#defining list\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"\n",
"#empty dictionary and input \n",
"inventory = {}\n",
"\n",
"for item in products:\n",
" quantity = int(input(f\"Please insert inventory count for {item} avalable\"))\n",
" inventory[item] = quantity\n",
"\n",
"#create an empty set\n",
"customer_orders = set()\n",
"\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"## can also do this wiht a for loop and range .. need to look at this. \n",
"\n",
"\n",
"#need to figure out the statistics\n",
"total_products_ordered = len(customer_orders)\n",
"percentage_ordered = (total_products_ordered / len(products)) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"print(total_products_avaliable)\n",
"\n",
"print(f\" Customer ordered {total_products_ordered} products\")\n",
"print(f\" Customer order made up {percentage_ordered} percentage of the total avalable orders\")\n",
"\n",
"\n",
"#print order statistcis \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",
"\n",
"#correct the original inventory\n",
"for product in customer_orders:\n",
" inventory[product] -= 1\n",
"\n",
"\n",
"#print in individual lines\n",
"\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\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"BELOW IS THE LAB REVIEW DONE BY FRED"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#clean code -- From the above setup | completed by Fred\n",
"\n",
"\n",
"#1\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"\n",
"#2\n",
"inventory = {}\n",
"\n",
"#3\n",
"quantity = int(input(\"Select the quantity of t-shirts to add to inventory: \"))\n",
"inventory[\"t-shirt\"] = quantity\n",
"\n",
"quantity = int(input(\"Select the quantity of mug to add to inventory: \"))\n",
"inventory[\"mug\"] = quantity\n",
"\n",
"quantity = int(input(\"Select the quantity of hat to add to inventory: \"))\n",
"inventory[\"hat\"] = quantity\n",
"\n",
"quantity = int(input(\"Select the quantity of book to add to inventory: \"))\n",
"inventory[\"book\"] = quantity\n",
"\n",
"quantity = int(input(\"Select the quantity of keychain to add to inventory: \"))\n",
"inventory[\"keychain\"] = quantity\n",
"\n",
"\n",
"#4\n",
"customer_orders = set()\n",
"\n",
"#5\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"product_name = input(\"Enter the name of a product the customer wants to order: \")\n",
"customer_orders.add(product_name)\n",
"\n",
"#6\n",
"print(\"Products in customer orders: \", 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(f\"Percentage of Products ordered: {order_status[1]} %\")\n",
"\n",
"#9\n",
"#updating qnty for each ordered product\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -= 1\n",
"\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -= 1\n",
"\n",
"product_name = customer_orders.pop()\n",
"inventory[product_name] -= 1\n",
"\n",
"#10\n",
"\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": "data-analytics",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +238,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.23"
}
},
"nbformat": 4,
Expand Down