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
86 changes: 84 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,93 @@
"\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": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'t-shirt': 12, 'mug': 2, 'hat': 3, 'book': 4, 'keychain': 5}\n",
"{'hat', 'book', 'mug'}\n",
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0\n",
"('t-shirt', 12)\n",
"('mug', 1)\n",
"('hat', 2)\n",
"('book', 3)\n",
"('keychain', 5)\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"\n",
"for product in products:\n",
" quantity = int(input(\"Insert Quantity of: \" + product + \"s\"))\n",
" inventory[product] = quantity\n",
" \n",
"print(inventory)\n",
"\n",
"customer_orders = set()\n",
"\n",
"while len(customer_orders) < 3:\n",
" if len(customer_orders) == 0:\n",
" order = input(\"Select the first product out of the products list: \")\n",
" \n",
" if order in products:\n",
" customer_orders.add(order)\n",
" \n",
" else:\n",
" print(\"Invalid product. Please choose one from the list.\")\n",
" \n",
" elif len(customer_orders) == 1:\n",
" order = input(\"Select the second product out of the products list: \")\n",
" \n",
" if order in products:\n",
" customer_orders.add(order)\n",
" \n",
" else:\n",
" print(\"Invalid product. Please choose one from the list.\")\n",
"\n",
" else:\n",
" order = input(\"Select the third and last product out of the products list: \")\n",
"\n",
" if order in products:\n",
" customer_orders.add(order)\n",
" \n",
" else:\n",
" print(\"Invalid product. Please choose one from the list.\")\n",
"\n",
"print(customer_orders)\n",
"\n",
"total_products_ordered = len(customer_orders)\n",
"total_available_prodcuts = len(products)\n",
"percentage_ordered = (total_products_ordered / total_available_prodcuts) * 100\n",
"\n",
"order_status = (total_products_ordered, percentage_ordered)\n",
"\n",
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", total_products_ordered)\n",
"print(\"Percentage of Products Ordered:\", percentage_ordered)\n",
"\n",
"for item in customer_orders:\n",
" #inventory.pop(item)\n",
" inventory[item] -= 1\n",
"\n",
"for items in inventory.items():\n",
" print(items)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +150,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down