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
72 changes: 70 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,79 @@
"\n",
"Solve the exercise by implementing the steps using the Python concepts of lists, dictionaries, sets, and basic input/output operations. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Ask the user to input the quantity of each product available in the inventory. Use the product names from the `products` list as keys in the `inventory` dictionary and assign the respective quantities as values.\n",
"\n",
"4. Create an empty set called `customer_orders`.\n",
"\n",
"5. Ask the user to input the name of three products that a customer wants to order (from those in the products list, meaning three products out of \"t-shirt\", \"mug\", \"hat\", \"book\" or \"keychain\". Add each product name to the `customer_orders` set.\n",
"\n",
"6. Print the products in the `customer_orders` set.\n",
"\n",
"7. Calculate the following order statistics:\n",
" - Total Products Ordered: The total number of products in the `customer_orders` set."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Customer Orders:\n",
"\n",
"Inventory:\n",
"{'t-shirt': 34, 'mug': 56, 'hat': 87, 'book': 56, 'keychain': 45}\n"
]
}
],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]\n",
"inventory = {}\n",
"quantity1 = int(input(\"Enter the quantity of a product:\"))\n",
"inventory[\"t-shirt\"] = quantity1\n",
"\n",
"quantity2 = int(input(\"Enter the quantity of a product:\"))\n",
"inventory[\"mug\"] = quantity2\n",
"\n",
"quantity3 = int(input(\"Enter the quantity of a product:\"))\n",
"inventory[\"hat\"] = quantity3\n",
"\n",
"quantity4 = int(input(\"Enter the quantity of a product:\"))\n",
"inventory[\"book\"] = quantity4\n",
"\n",
"quantity5 = int(input(\"Enter the quantity of a product:\"))\n",
"inventory[\"keychain\"] = quantity5\n",
"\n",
"\n",
"customer_orders = set()\n",
"product1 = (input(\"Input the name of a product:\"))\n",
"customer_orders.add(product1)\n",
"\n",
"product2 = (input(\"Input the name of a product:\"))\n",
"customer_orders.add(product2)\n",
"\n",
"product3 = (input(\"Input the name of a product:\"))\n",
"customer_orders.add(product3)\n",
"\n",
"print(\"\\nCustomer Orders:\")\n",
"\n",
"print(\"\\nInventory:\")\n",
"print(inventory)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +136,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.9"
}
},
"nbformat": 4,
Expand Down