Skip to content
Open

lab 1 #650

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
127 changes: 125 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,134 @@
"\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": 14,
"metadata": {},
"outputs": [],
"source": [
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"inventory [\"t-shirt\"] = int(input(\"Enter the quantity of t-shirts: \"))\n",
"inventory [\"mug\"] = int(input(\"Enter the quantity of mugs: \"))\n",
"inventory [\"hat\"] = int(input(\"Enter the quantity of hats: \"))\n",
"inventory [\"book\"] = int(input(\"Enter the quantity of books: \"))\n",
"inventory [\"keychain\"] = int(input(\"Enter the quantity of keychains: \"))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer order: {'book', 'hat', 'mug'}\n"
]
}
],
"source": [
"customer_orders.add(input(\"Enter the first product you want to order: \"))\n",
"customer_orders.add(input(\"Enter the second product you want to order: \"))\n",
"customer_orders.add(input(\"Enter the third product you want to order: \"))\n",
"print(\"Customer order:\", customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"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"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics: \n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.0\n"
]
}
],
"source": [
"print(\"Order Statistics: \")\n",
"print(\"Total Products Ordered: \", total_products_ordered)\n",
"print(\"Percentage of Products Ordered: \", percentage_ordered)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory: {'t-shirt': 19, 'mug': 10, 'hat': 0, 'book': 7, 'keychain': 2}\n"
]
}
],
"source": [
"inventory [\"t-shirt\"] = inventory [\"t-shirt\"] - 1 \n",
"inventory [\"mug\"] = inventory [\"mug\"] - 1 \n",
"inventory [\"hat\"] = inventory [\"hat\"] - 1 \n",
"inventory [\"book\"] = inventory [\"book\"] - 1 \n",
"inventory [\"keychain\"] = inventory [\"keychain\"] - 1\n",
"\n",
"print(\"Updated Inventory:\", inventory)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +191,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down