Skip to content

Week1 lab1 done #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
153 changes: 151 additions & 2 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,155 @@
"# Lab | Data Structures "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"#1: Define the products\n",
"products = [\"t-shirt\", \"mug\", \"hat\", \"book\", \"keychain\"]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"#2: Create empty inventory dictionary\n",
"inventory = {}"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"#3: Ask user for quantity of each product\n",
"for product in products:\n",
" quantity = int(input(f\"Enter quantity available for {product}: \"))\n",
" inventory[product] = quantity"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"#4: Create empty set for customer orders\n",
"customer_orders = set()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"#5:Ask the user to input 3 products they want to order\n",
"order1 = input(\"Enter product #1 to order: \")\n",
"order2 = input(\"Enter product #2 to order: \")\n",
"order3 = input(\"Enter product #3 to order: \")"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"#6:Clean the inputs (remove whitespace and make lowercase)\n",
"order1 = order1.strip().lower()\n",
"order2 = order2.strip().lower()\n",
"order3 = order3.strip().lower()\n",
"customer_orders = {order1, order2, order3} & set(products)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Customer Orders: {'hat', 'keychain', 'book'}\n"
]
}
],
"source": [
"# Step 7: Print customer_orders\n",
"print(\"Customer Orders:\", customer_orders)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Order Statistics:\n",
"Total Products Ordered: 3\n",
"Percentage of Products Ordered: 60.00%\n"
]
}
],
"source": [
"# Step 8: Calculate and print order statistics\n",
"total_ordered = len(customer_orders)\n",
"total_products = len(products)\n",
"percent_ordered = (total_ordered / total_products) * 100\n",
"order_status = (total_ordered, f\"{percent_ordered:.2f}%\")\n",
"\n",
"print(\"Order Statistics:\")\n",
"print(\"Total Products Ordered:\", order_status[0])\n",
"print(\"Percentage of Products Ordered:\", order_status[1])"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"# Step 9: Update inventory by reducing quantity of each ordered product by 1\n",
"for item in customer_orders:\n",
" if inventory[item] > 0:\n",
" inventory[item] -= 1"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Updated Inventory:\n",
"t-shirt: 9\n",
"mug: 8\n",
"hat: 6\n",
"book: 5\n",
"keychain: 4\n"
]
}
],
"source": [
"# Step 10: Print updated inventory\n",
"print(\"Updated Inventory:\")\n",
"for product, qty in inventory.items():\n",
" print(f\"{product}: {qty}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -54,7 +203,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -68,7 +217,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.5"
}
},
"nbformat": 4,
Expand Down